Algorithms and complexity
Practice explaining correctness and complexity before coding.
Use representative edge cases and distinguish worst-case from expected complexity.
Interview questions
Choose a question to reveal its answer.
01EasyCoreHow do you explain the time complexity of an algorithm?
Answer
How do you explain the time complexity of an algorithm?
Describes how operation count grows with input size asymptotically.
Explain why scanning a list scales linearly.
def two_sum(nums, target):
seen = {}
for i, x in enumerate(nums):
if target-x in seen:
return [seen[target-x], i]
seen[x] = i
return []Expected O(n) time and O(n) auxiliary space.
02EasyCoreHow do you calculate auxiliary space complexity?
Answer
How do you calculate auxiliary space complexity?
Describes how memory usage grows with input size under a stated convention.
Account for an extra hash map used by an algorithm.
03EasyCoreWhy can a hash map solve Two Sum efficiently?
Answer
Why can a hash map solve Two Sum efficiently?
Key-value structure with expected efficient lookup under suitable hashing.
Find a complement in the two-sum problem.
04MediumHigh priorityWhat precondition does binary search require?
Answer
What precondition does binary search require?
Repeatedly halves a sorted search space or monotonic predicate interval.
Locate an insertion point in a sorted list.
05MediumHigh priorityWhen would you use a stack?
Answer
When would you use a stack?
Last-in first-out abstract collection.
Match nested parentheses.
06MediumWhen would you use a queue?
Answer
When would you use a queue?
First-in first-out abstract collection.
Process breadth-first graph traversal.
07MediumHow does depth-first search traverse a graph?
Answer
How does depth-first search traverse a graph?
Explores along a path before backtracking.
Traverse a connected component recursively or with a stack.
08MediumWhy does BFS find shortest paths in unweighted graphs?
Answer
Why does BFS find shortest paths in unweighted graphs?
Explores graph layers in increasing edge distance from a start.
Find shortest paths in an unweighted graph.
09HardWhen is dynamic programming applicable?
Answer
When is dynamic programming applicable?
Stores solutions to overlapping subproblems with optimal substructure where applicable.
Compute minimum coin count using smaller amounts.
10HardHow do heaps help solve top-k problems?
Answer
How do heaps help solve top-k problems?
Priority structure supporting efficient access to a minimum or maximum element.
Maintain the largest k items using a size-k min heap.
Priority and difficulty are editorial study recommendations.
Technical reference: Documentation / paper ↗
Try a few practice questions
Explore the questions before creating a free account.
1. What is the time complexity of binary search on a sorted array?
2. Which data structure supports breadth-first graph traversal?
3. What is expected time complexity of two-sum using a hash map with suitable hashing?
SQL interview patterns
Continue to the next set of interview questions.