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
- DSA Introduction
- Big O Notation
- Arrays and Strings
- Hashing: Hash Maps and Sets
- Two Pointers
- Sliding Window
- Prefix Sums
- Kadane’s Algorithm: Maximum Subarray
- Binary Search
- Sorting Basics
- Merge Sort and Quick Sort
- Recursion
- Backtracking
- Linked Lists
- Fast and Slow Pointers
- Stacks
- Monotonic Stack
- Queues and Deques
- Binary Trees and Traversals
- Binary Search Trees
- Heaps and Priority Queues
- Graphs: BFS and DFS
- Grid Problems (Flood Fill and BFS)
- Topological Sort
- Shortest Paths (Dijkstra)
- Dynamic Programming (1D)
- 2D Dynamic Programming
- Greedy Algorithms and Intervals
- The DSA Interview Playbook
Sample questions with answers
1. What's the secret to solving many interview problems?
- Recognising a small set of patterns
- Typing fast
- 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?
- O(1)
- O(n)
- O(n²)
Show answer
B. O(n) — Work grows linearly with input size.
3. Reading arr[i] costs…
- O(n)
- O(1)
- O(log n)
Show answer
B. O(1) — The address is computed directly.
4. Average lookup in a hash set is…
- O(log n)
- O(n)
- O(1)
Show answer
C. O(1) — That's why "seen before?" checks use sets.
5. Converging two pointers usually needs…
- A tree
- A sorted array
- 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"?
- Contiguous subarrays/substrings with a condition (longest, shortest, sum)
- Sorting problems
- 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…
- prefix[j+1] - prefix[i]
- arr[j] - arr[i]
- 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…
- Sorted order
- The minimum element
- 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…
- A linked list
- Sorted data (or a monotonic condition)
- A hash map
Show answer
B. Sorted data (or a monotonic condition) — Each step halves the search space.
10. Insertion sort is good for…
- Huge random arrays
- Small or nearly sorted arrays
- Linked lists only
Show answer
B. Small or nearly sorted arrays — Nearly sorted input runs close to O(n).