Same code takes highly variable amount of time across runs

This is regarding my solutions for the following problem:
https://leetcode.com/problems/next-greater-element-ii

I have spent a good amount of time trying to optimize my time taken aiming for the "Your code has beat 100% of the other solutions". But it turns out that the same code can take anywhere between 180ms and 400ms and those numbers are meaningless. I even tried copy pasting the best solution (148ms) and it took 336ms to run.

Please take a look into this. It wastes a lot of time for candidates trying to improve their solutions.

Comments (16)