DEV Community

Tushar Tushar
Tushar Tushar

Posted on

Hacking Leetcode runtimes!!

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

Top comments (0)

👋 Kindness is contagious

Dive into this insightful write-up, celebrated within the collaborative DEV Community. Developers at any stage are invited to contribute and elevate our shared skills.

A simple "thank you" can boost someone’s spirits—leave your kudos in the comments!

On DEV, exchanging ideas fuels progress and deepens our connections. If this post helped you, a brief note of thanks goes a long way.

Okay