Bug in executing program


When selecting custom input and running the code, answer is correct. Not when submitting.


here too, python code…


Custom input test runs a single test. Test and Submit run multiple tests, so if you don’t reinitialize any global variables at the start of every test, it can give incorrect answers. This is not intuitively obvious; I wouldn’t know it if someone hadn’t mentioned it in comments.