Hacking Leetcode runtimes!!

Tushar Tushar - Feb 24 - - Dev Community

In my opinion it is way bigger achievement than actually solving that particular problem in the lowest time whoever did this, you my friend.. you have earned my respect!!

While working through a recent LeetCode problem after solving it I went on to check out the best solutions and other ways to solve the problem and I came across one really bright mind.
One of the solutions had a piece of code that reverse-engineered how LeetCode displays runtime results. Yep, someone actually figured out a way to modify the runtime display to always show 0 ms, regardless of the actual performance of the algorithm.
This code essentially manipulates the system and writes "0" into a file when the program exits, effectively "hiding" the real performance.
it uses a module called atexit i.e. "at exit" which then receives a function to register and unregistered cleanup functions, and then it takes a lambda function which opens the "display_runtime.txt" and writes 0 to it.

Screenshot from leetcode solution

Screenshot about the atexit package

. . . . .