See how fast each complexity class grows, plot any expression you type, and read off the largest input a solution can handle before it times out.
A judge runs roughly 10⁸ simple operations a second. That single number
turns a constraint like n ≤ 10⁵ into the complexity the interviewer expects —
read the last column backwards.
Budget:
Which grows faster, are they the same class, and from what n does the difference actually show? Every variable is treated as n.
The fastest way to the intended solution is the bound on n. At ~10⁸ operations a second, this is what each size allows.
| If n is up to | Aim for | Usually means |
|---|---|---|
| 10 – 11 | O(n!) | Every permutation: backtracking, brute-force ordering. |
| 20 – 25 | O(2ⁿ), O(n·2ⁿ) | Every subset: include / exclude recursion, bitmask DP. |
| ≈ 500 | O(n³) | Interval DP, Floyd–Warshall, three nested loops. |
| ≈ 5,000 | O(n²) | 2-D DP over two indices (LCS, edit distance), all pairs. |
| 10⁵ – 10⁶ | O(n log n) | Sort first, a heap, binary search inside a loop. The most common interview bound. |
| 10⁷ – 10⁸ | O(n) | One pass: hash map, two pointers, sliding window, prefix sums, BFS / DFS. |
| beyond 10⁸ | O(log n), O(1) | Binary search on the answer, math, a formula. |
Recognise the code shape and you know the bound before you count anything.
3n² + 10n + 7 is
O(n²). Two passes over the array is still O(n).O(a + b); a loop inside a loop is O(a · b).O(m · n), not O(n²); a graph is O(V + E). Collapsing
them to n is the most common way to state a wrong bound.log n. The base
never matters: log₂ n and log₁₀ n differ by a constant.O(2ⁿ). Memoise it and each state is computed once:
O(states × work per state) = O(n).O(n log n)
(merge sort). Split in half and keep one side — O(log n) (binary search).O(1) per operation over
the run — say "amortised" out loud.O(n)
space even with no data structure in sight; on a balanced one it is O(log n).O(n log n) and everything after
it is linear, so the total is O(n log n)" is the sentence an interviewer is
listening for.