DEV Community

geyuqiu
geyuqiu

Posted on

Leetcode TLE explained

Time limit exceeded (TLE) can be one of the most frustrating results when working on hard problems on Leetcode.

Most of the easy and medium problems on Leetcode do not have any time constraints regarding how complex your algorithm should be, as long as you get all of the test cases right. However, you should make sure that your solution time complexity is somewhere between O(n^2) and O(n).

In my experience, we have a time constraint on hard problems that is between O(nlogn) and O(n). If you get a TLE, look at your algorithm and calculate the complexity. This means your algorithm should be at least faster than merge sort. If you have any problems there, please take a look at these 2 books: cracking the coding interview and elements of programming interviews

If you have any questions, write me something :)
And keep updated on my channel!

Top comments (0)