Time difference in PyPy when using same variable vs a new variable

Viewed 48

I was going through an easy problem on codechef (https://www.codechef.com/problems/ANUWTA) and I saw these submissions:

[This submission had a time limit exceeded][1][1]: https://i.stack.imgur.com/mVnMr.png

while another similar submission [is the right answer][2] [2]: https://i.stack.imgur.com/4LCEE.png

I do not get why there is 1.5 seconds difference between these two. The initial guess was maybe type casting.

The link to the submissions:

https://www.codechef.com/viewsolution/52161454

https://www.codechef.com/viewsolution/52161477

These are not my submissions.

1 Answers

It doesn't make sense to me, and I cannot reproduce the time difference locally either. Given that both script are spending more than 99% of their time doing I/O, I guess the 2 seconds version was just the machine being randomly busy, e.g. writing the output to disk or something.

Related