Introduction
It's been a while I have been solving Leetcode problems. I always notice that Leetcode says my code sucks by showing me the image given below.
Digging deep into the matter
Let's say you are solving a hard problem, which requires you to think about more optimal approach. You bring down the complexity from O(n^2) to O(nlogn) or better => O(n). Or just O(1) (Who knows lol!). And suddenly you went from beats 5% to beats 100%! Which is amazing. You actually solved the problem the right way!
But let's say you are just warming up. You know the problem will be solved in O(n) only. You code it the right way. Optimized and removed unnecessary calculations and still your solution beats 5%. It is taking around 500ms more.
When you look at the 100% beats solutions, they have done some nasty optimizations on low level (like, on reading input etc), but for the solutions which are just same as yours beat you. In that case, the runtime estimations become unreliable.
Conclusion
Look at the top solutions to know what low level optimizations are done and practice them. Learn to implement them. If you have something better, then congrats. Else, just move to the next problem.
Top comments (1)
as you say my friendly neighbourhood developer πΈοΈπ»