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

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more