Almost every coding interview ends with "what's the time and space complexity?" Many candidates who solved the problem cleanly then lose points by guessing, hedging or getting space wrong. A short, repeatable way of answering fixes that.
"O(n log n)" on its own sounds memorised. "We sort once, O(n log n), then a single pass, O(n), so the sort dominates" shows you derived it. Name what n is, too, especially when there are two inputs: O(m + n) and O(m · n) are very different answers.
s += c in a loop can be O(n²) in some languages; a list-and-join is O(n).arr[1:] in a recursive call copies; that adds O(n) per call.list.remove, in on a list, and indexOf are linear.| Pattern | Typical time |
|---|---|
| Single pass / two pointers | O(n) |
| Sort then scan | O(n log n) |
| Binary search on sorted data | O(log n) |
| Heap of size k over n items | O(n log k) |
| BFS/DFS on a graph | O(V + E) |
| Backtracking over subsets | O(2ⁿ) |
Ask yourself what the lower bound is. If you must look at every element, you can't beat O(n); say so confidently rather than hunting for a trick that doesn't exist. If the bottleneck is repeated lookups, a hash map or precomputation usually helps. If it's sorting, ask whether the input range is small enough for counting sort.
Disclosure: I'm with the team at Linkjob AI, a real-time interview assistant. This guide is general and product-independent.