Big-O answers one question: when the input gets 10x bigger, how much slower does your code get?
The ladder (best → worst)
- O(1) — constant. Array index, hashmap lookup. 10x data → same speed
- O(log n) — halving. Binary search. 1M items → ~20 steps
- O(n) — linear. One loop. 10x data → 10x time
- O(n log n) — good sorts (merge/quick)
- O(n²) — nested loops. 10x data → 100x time. 100k items → trouble
- O(2ⁿ) — naive recursion (fib). Dead by n=40
Reading your own code
for (const x of arr) // O(n)
for (const y of arr) // × O(n) = O(n²)
for (const x of arr) { ... } // O(n)
for (const y of arr) { ... } // + O(n) = O(n) — sequential adds, nested multipliesThe classic upgrade
Two Sum brute force = nested loops O(n²). With a hashmap: one loop, O(1) lookups → O(n). This exact upgrade is what interviewers wait for — solve it on our judge.
Rules: drop constants (O(2n)=O(n)), keep the dominant term (O(n²+n)=O(n²)).
← All Articles