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

  1. Two Sum
  2. Contains Duplicate
  3. Valid Anagram
  4. Group Anagrams
  5. Top K Frequent Elements
  6. Product of Array Except Self
  7. Longest Consecutive Sequence
  8. Valid Palindrome
  9. Container With Most Water
  10. 3Sum
  11. Trapping Rain Water
  12. Best Time to Buy and Sell Stock
  13. Longest Substring Without Repeating Characters
  14. Minimum Window Substring
  15. Subarray Sum Equals K
  16. Maximum Subarray
  17. Binary Search
  18. Search in Rotated Sorted Array
  19. Koko Eating Bananas
  20. Valid Parentheses
  21. Min Stack
  22. Daily Temperatures
  23. Largest Rectangle in Histogram
  24. Reverse Linked List
  25. Merge Two Sorted Lists
  26. Linked List Cycle
  27. LRU Cache
  28. Maximum Depth of Binary Tree
  29. Invert Binary Tree
  30. Binary Tree Level Order Traversal
  31. Validate Binary Search Tree
  32. Lowest Common Ancestor of a Binary Tree
  33. Kth Largest Element in an Array
  34. Merge k Sorted Lists
  35. Number of Islands
  36. Rotting Oranges
  37. Course Schedule
  38. Network Delay Time
  39. Word Ladder
  40. Subsets
  41. Permutations
  42. Combination Sum
  43. Climbing Stairs
  44. House Robber
  45. Coin Change
  46. Longest Increasing Subsequence
  47. Longest Common Subsequence
  48. Edit Distance
  49. Merge Intervals
  50. Meeting Rooms II
  51. Jump Game

Sample questions with answers

1. What's the optimal time for Two Sum?

  1. O(n²) is the best possible
  2. O(n) with a hash map
  3. O(log n)
Show answer

B. O(n) with a hash map — Store value → index; look up target - x.

2. Fastest general approach?

  1. Nested loops
  2. A set: return True when a number is already in it
  3. 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…

  1. They have the same length only
  2. They're reverses
  3. 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?

  1. The sorted word (or a letter-count tuple)
  2. The word length
  3. The first letter
Show answer

A. The sorted word (or a letter-count tuple) — 'eat', 'tea', 'ate' → 'aet'.

5. First step?

  1. Reverse it
  2. Sort the array
  3. Count frequencies with a hash map
Show answer

C. Count frequencies with a hash map — Counter(nums).

6. Why not divide the total product?

  1. Division isn't allowed and zeros break it
  2. It's O(n²)
  3. Division is slow
Show answer

A. Division isn't allowed and zeros break it — Use prefix and suffix products.

7. Key trick?

  1. Use a heap
  2. Put numbers in a set and start counting only from sequence starts (x-1 not in set)
  3. 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?

  1. Only vowels
  2. Only letters and digits, ignoring case
  3. 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…

  1. max(h[i], h[j]) × (j - i)
  2. h[i] + h[j]
  3. 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?

  1. Sort the array
  2. Reverse it
  3. Build a hash set
Show answer

A. Sort the array — Then two-pointer for each fixed number.