Python 3 gave TLE, but Python 2 gave AC


I just gave the 3 hr practice test on interviewbit.
For the third Q, my code for python3 gave TLE, but when I copied the same code into python 2, it gave an Accept.
Please look into this. This is actually a very frequent occurrence on InterviewBit, where python solutions tend to give TLE for the correct logic.