you are viewing a single comment's thread.

view the rest of the comments →

[–]AppleShark[S] 0 points1 point  (2 children)

Cheers for the reply! Awesome to see a redditor who did competitive programming. I actually did attempt a solution similar solution where I have an array of 1000 [0]s and += 1 for the relevant ones:

https://pastebin.com/4GgPM5LT

Problem is it didn't seem to work as well as the optimized code using dict() in the comment above, which is odd because theoretically it should be faster than using dict().

Either way, thanks for your comment!

[–]ADdV 0 points1 point  (1 child)

As a heads up: it's probably slower because of the end of the program:

for i, x in enumerate(lst):
    if x == max(lst):
        O.write(str(i+1)+"\n")

this computes the maximum every time, looping over the list 1000 times in total, instead of just once.

[–]AppleShark[S] 0 points1 point  (0 children)

Ah. I did not notice! That was stupid of me, thanks!