Coding Interview MCQ Test
20 random MCQs on classic coding interview problems with answers: Two Sum, sliding window, binary search, stacks, linked lists, trees, graphs, heaps, backtracking and DP.
- 20 random questions
- 20 minutes
- 153 in the question bank
No sign-up needed. Answers and explanations are shown at the end.
About this test
These questions come from the classic interview problems asked at product companies: which approach solves the problem, what its complexity is, and which edge case breaks a naive solution.
Use it after the DSA test, when you are practising real problems.
Each attempt picks new questions at random from the question bank. You can go back and change answers until you finish or the timer runs out. At the end you see your score, the right answer and a short explanation for every question, and the lessons to revise for the ones you missed.
Topics covered
- Two Sum
- Contains Duplicate
- Valid Anagram
- Group Anagrams
- Top K Frequent Elements
- Product of Array Except Self
- Longest Consecutive Sequence
- Valid Palindrome
- Container With Most Water
- 3Sum
- Trapping Rain Water
- Best Time to Buy and Sell Stock
- Longest Substring Without Repeating Characters
- Minimum Window Substring
- Subarray Sum Equals K
- Maximum Subarray
- Binary Search
- Search in Rotated Sorted Array
- Koko Eating Bananas
- Valid Parentheses
- Min Stack
- Daily Temperatures
- Largest Rectangle in Histogram
- Reverse Linked List
- Merge Two Sorted Lists
- Linked List Cycle
- LRU Cache
- Maximum Depth of Binary Tree
- Invert Binary Tree
- Binary Tree Level Order Traversal
- Validate Binary Search Tree
- Lowest Common Ancestor of a Binary Tree
- Kth Largest Element in an Array
- Merge k Sorted Lists
- Number of Islands
- Rotting Oranges
- Course Schedule
- Network Delay Time
- Word Ladder
- Subsets
- Permutations
- Combination Sum
- Climbing Stairs
- House Robber
- Coin Change
- Longest Increasing Subsequence
- Longest Common Subsequence
- Edit Distance
- Merge Intervals
- Meeting Rooms II
- Jump Game
Sample questions with answers
1. What's the optimal time for Two Sum?
- O(n²) is the best possible
- O(n) with a hash map
- O(log n)
Show answer
B. O(n) with a hash map — Store value → index; look up target - x.
2. Fastest general approach?
- Nested loops
- A set: return True when a number is already in it
- Sort and binary search
Show answer
B. A set: return True when a number is already in it — O(n) time, O(n) space.
3. Two strings are anagrams when…
- They have the same length only
- They're reverses
- They have the same letter counts
Show answer
C. They have the same letter counts — Counter(s) == Counter(t).
4. What key groups anagrams together?
- The sorted word (or a letter-count tuple)
- The word length
- The first letter
Show answer
A. The sorted word (or a letter-count tuple) — 'eat', 'tea', 'ate' → 'aet'.
5. First step?
- Reverse it
- Sort the array
- Count frequencies with a hash map
Show answer
C. Count frequencies with a hash map — Counter(nums).
6. Why not divide the total product?
- Division isn't allowed and zeros break it
- It's O(n²)
- Division is slow
Show answer
A. Division isn't allowed and zeros break it — Use prefix and suffix products.
7. Key trick?
- Use a heap
- Put numbers in a set and start counting only from sequence starts (x-1 not in set)
- Sort and count
Show answer
B. Put numbers in a set and start counting only from sequence starts (x-1 not in set) — Each number is visited a constant number of times.
8. Which characters are compared?
- Only vowels
- Only letters and digits, ignoring case
- All characters
Show answer
B. Only letters and digits, ignoring case — 'A man, a plan…' is valid.
9. Area between lines i and j is…
- max(h[i], h[j]) × (j - i)
- h[i] + h[j]
- min(h[i], h[j]) × (j - i)
Show answer
C. min(h[i], h[j]) × (j - i) — Water is limited by the shorter line.
10. First step?
- Sort the array
- Reverse it
- Build a hash set
Show answer
A. Sort the array — Then two-pointer for each fixed number.