Complexity analysis interview questions
Big O in plain words, reading the cost of loops and recursion, amortised and space costs, what Python's built-in operations really cost, and which input sizes fit which algorithms.
– interview-ready · 14 questions in this topic
– of 14 tried
Saved on this device. Interview-ready means you got it right on two different days. Guesses and hints count for less.
Questions
- Big O in plain wordsPredict
- Reading the cost of loopsPredict
- Where O(log n) comes fromPredict
- Amortised cost: cheap on average, sometimes slowPredict
- Space complexity and the call stackPredict
- What common Python operations costPredict
- Which complexity fits which input sizePredict
- Best, average and worst casePredict
Practise this topic
Flashcards · 24
Flip, then say if you knew it. Needs JavaScript; every answer is also on its question page.
Quick quiz · 14 questions
One exercise per question, checked as you go. Needs JavaScript.
Mock interview · 2 sets
Timed, out loud, then tick what you covered. Needs JavaScript.
Quick facts
Recall the answer first, then tap Show to check.
x in listcostMembership in a list scans items one by one: O(n). In a set or dict it is O(1) on average.
list.insert(0, x)costInserting or deleting at the front of a list shifts every other item: O(n).
deque.appendleftis O(1).stris immutablePython strings cannot change, so
s += tin a loop may copy the growing string each time;''.join(parts)builds it once in O(total length).sorted()costPython's sort is O(n log n) comparisons in the worst case and close to O(n) on input that is already mostly in order.
pow(b, e, m)The built-in three-argument
powcomputes modular powers by repeated squaring in O(log e) multiplications.
Printable cheat sheet · Review your weak spots in this topic
Share your progress
Sources: Topic outline informed by the Tech Interview Handbook by Yangshun Tay and the NeetCode 150 pattern grouping by neetcode-gh, both MIT licensed. Every problem, solution and explanation is written by Best Latest Apps. Credits and license