Interview Questions

Conceptual questions with the strong answer, green and red flags, follow-ups and related concepts. Filter by difficulty, topic, pattern or the skill being tested.

22 questions
Tier 2 · essentialIntermediate
Recognizing the approach from an array and a target
Given an array and a target, how would you determine which algorithmic approach to use?
Tier 2 · essentialIntermediate
Deciding whether O(n²) can be improved
Your first solution is O(n²). How would you determine whether it can be improved?
Tier 3 · essentialAdvanced
Choosing between BFS, DFS, Dijkstra and DP
How do you decide between BFS, DFS, Dijkstra, and Dynamic Programming?
Tier 1Beginner
Hash map or array?
When would you use a hash map instead of an array, and when is an array the better choice?
Tier 1Beginner
Stack versus queue
What is the difference between a stack and a queue, and how do you decide which one a problem needs?
Tier 1Beginner
Where does O(n log n) come from?
Explain what O(n log n) means and where the log factor typically comes from.
Tier 1Beginner
Array versus linked list
When would you choose a linked list over an array, and when is that choice wrong?
Tier 1Intermediate
Recursion versus iteration
When is recursion the right tool, when is iteration better, and what does recursion cost?
Tier 1Intermediate
Average case versus worst case
Hash table lookups and quicksort are both called fast. What do average-case and worst-case guarantees mean for each, and when does the difference matter?
Tier 1Intermediate
When space complexity matters
Interviewers ask about space complexity. When does it actually matter, and how do you reason about it?
Tier 2Intermediate
Questions to ask before binary searching
Before applying binary search, what questions do you ask yourself?
Tier 2Intermediate
Recognizing a sliding-window problem
How do you recognize that a problem calls for a sliding window, and when does the pattern fail?
Tier 2Intermediate
Two pointers or hash map?
A problem asks for pairs or triples meeting a condition. How do you choose between two pointers and a hash map?
Tier 2Intermediate
Top K from a stream
You receive numbers one at a time and must report the K largest at any point. How do you approach it?
Tier 2Intermediate
Next greater element and the monotonic stack
For each element, find the next element to its right that is greater. What is the right approach, and why is it O(n) even though it has a nested loop?
Tier 2Intermediate
Prefix sum or segment tree?
You must answer many range-sum queries on an array. When is a prefix-sum array enough, and when do you need a segment tree or Fenwick tree?
Tier 2Intermediate
When a hash map is the wrong choice
Hash maps are the default answer to many problems. Describe situations where a hash map is the wrong choice and what you would use instead.
Tier 3Advanced
Choosing a shortest-path algorithm
You are given a graph and asked for shortest paths. Walk me through how you choose the algorithm.
Tier 3Advanced
Recognizing a dynamic-programming problem
How do you recognize that a problem needs dynamic programming, and how do you go from recognition to a working solution?
Tier 3Advanced
Greedy or dynamic programming?
A problem looks like it could be greedy. How do you decide whether greedy is correct or whether you need DP?
Tier 3Advanced
Union-Find or DFS for connectivity?
You need to answer connectivity questions on a graph. When do you use Union-Find, and when is DFS/BFS the better tool?
Tier 3Expert
Convincing me your algorithm is correct
You have written an algorithm. How do you convince me it is correct without running it on every input?