LeetCode Execution Time Calculation Bug Identified

🚨 Potential Bug Identified in LeetCode Execution Time Calculation 🚨 I recently noticed an issue with how LeetCode calculates and displays code execution time. By adding a simple static block with a shutdown hook, it is possible to alter the displayed runtime of a submitted solution. This indicates that the execution time can be influenced outside the actual algorithm logic, which should ideally not be possible. Below is the code snippet that demonstrates this behavior: static { Runtime.getRuntime().addShutdownHook(new Thread(() -> { try (FileWriter writer = new FileWriter("display_runtime.txt")) { writer.write("0"); } catch (IOException e) { e.printStackTrace(); } })); } This suggests a bug on LeetCode’s end, where execution time tracking may be relying on artifacts that can be manipulated during JVM shutdown. Sharing this for awareness and hoping the LeetCode team can look into it to ensure fair and accurate performance measurement for all submissions. hashtag #LeetCode #Java #TimeComplexity #Algorithms #CompetitiveProgramming #SoftwareEngineering #Programming #BugReport #DeveloperCommunity #TechLearning

  • graphical user interface, text

Even the problems that are impossible to solve in 0ms use this, just to get that 0ms tag 😂

Like
Reply

Yes , true Himanshu patidar , when i see 0ms code most of them have written this code snippet , leetcode should look into this matter , thanks for highlighting it .

It’s not new, it’s been there from like more than a year, probably topmost solution of every problem in Java has this thing

See more comments

To view or add a comment, sign in

Explore content categories