Look for built-in array methods like .includes(), .indexOf(), or .splice() being called inside a loop. These methods run hidden loops of their own.
O(N^2) Quadratic Time: Recognizing Inefficiencies
How do I spot hidden O(N^2) complexity?
The answer
More FAQs in O(N^2) Quadratic Time: Recognizing Inefficiencies
It is a time complexity where the execution time grows proportionally to the square of the input size, typically caused by checking every item against every other item.
No, only if both loops scale with N. If the outer loop runs N times and the inner loop runs a fixed 5 times, it is O(5N), which simplifies to O(N).
A TLE error on coding platforms almost always means you submitted an O(N^2) nested-loop solution when the platform was testing with a massive input expecting an O(N) solution.
Still have questions?
Browse all our FAQs or reach out to our support team
Want to upskill yourself?
Your learning library
Small steps. Big possibilities.
Find your next course. Build something great.