DSA MCQ Test

20 random data structures and algorithms MCQs with answers: Big O, arrays, hashing, two pointers, sliding window, binary search, sorting, recursion, linked lists, stacks, trees, heaps, graphs and DP.

  • 20 random questions
  • 20 minutes
  • 87 in the question bank

No sign-up needed. Answers and explanations are shown at the end.

About this test

Coding rounds start with recognising the pattern. These questions test exactly that: time complexity, which data structure fits, and which technique (two pointers, sliding window, BFS, dynamic programming) solves a problem.

It is a quick way to find which DSA topics to revise before your next round.

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. DSA Introduction
  2. Big O Notation
  3. Arrays and Strings
  4. Hashing: Hash Maps and Sets
  5. Two Pointers
  6. Sliding Window
  7. Prefix Sums
  8. Kadane’s Algorithm: Maximum Subarray
  9. Binary Search
  10. Sorting Basics
  11. Merge Sort and Quick Sort
  12. Recursion
  13. Backtracking
  14. Linked Lists
  15. Fast and Slow Pointers
  16. Stacks
  17. Monotonic Stack
  18. Queues and Deques
  19. Binary Trees and Traversals
  20. Binary Search Trees
  21. Heaps and Priority Queues
  22. Graphs: BFS and DFS
  23. Grid Problems (Flood Fill and BFS)
  24. Topological Sort
  25. Shortest Paths (Dijkstra)
  26. Dynamic Programming (1D)
  27. 2D Dynamic Programming
  28. Greedy Algorithms and Intervals
  29. The DSA Interview Playbook

Sample questions with answers

1. What's the secret to solving many interview problems?

  1. Recognising a small set of patterns
  2. Typing fast
  3. Memorising thousands of solutions
Show answer

A. Recognising a small set of patterns — Most problems are variations of ~15 patterns.

2. What is the time complexity of a single loop over n items?

  1. O(1)
  2. O(n)
  3. O(n²)
Show answer

B. O(n) — Work grows linearly with input size.

3. Reading arr[i] costs…

  1. O(n)
  2. O(1)
  3. O(log n)
Show answer

B. O(1) — The address is computed directly.

4. Average lookup in a hash set is…

  1. O(log n)
  2. O(n)
  3. O(1)
Show answer

C. O(1) — That's why "seen before?" checks use sets.

5. Converging two pointers usually needs…

  1. A tree
  2. A sorted array
  3. A hash map
Show answer

B. A sorted array — Move the left or right pointer based on the sum.

6. When do you think "sliding window"?

  1. Contiguous subarrays/substrings with a condition (longest, shortest, sum)
  2. Sorting problems
  3. Trees
Show answer

A. Contiguous subarrays/substrings with a condition (longest, shortest, sum) — Grow the right edge, shrink the left.

7. With prefix sums, the sum of arr[i..j] is…

  1. prefix[j+1] - prefix[i]
  2. arr[j] - arr[i]
  3. prefix[j] + prefix[i]
Show answer

A. prefix[j+1] - prefix[i] — O(1) per range query after O(n) setup.

8. Kadane's algorithm finds…

  1. Sorted order
  2. The minimum element
  3. The maximum subarray sum in O(n)
Show answer

C. The maximum subarray sum in O(n) — Extend the current sum or start fresh.

9. Binary search requires…

  1. A linked list
  2. Sorted data (or a monotonic condition)
  3. A hash map
Show answer

B. Sorted data (or a monotonic condition) — Each step halves the search space.

10. Insertion sort is good for…

  1. Huge random arrays
  2. Small or nearly sorted arrays
  3. Linked lists only
Show answer

B. Small or nearly sorted arrays — Nearly sorted input runs close to O(n).