🎯 Top 20 Data Structures & Algorithms Questions
Master coding interviews with the most frequently asked DSA questions from top tech companies
1. Two Sum - Find two numbers that add up to a target
EasyGiven an array of integers and a target sum, return indices of two numbers that add up to the target. You may assume that each input has exactly one solution.
2. Reverse a Linked List
EasyReverse a singly linked list iteratively and recursively. This is a fundamental linked list problem.
3. Valid Parentheses - Check if brackets are balanced
EasyGiven a string containing just the characters '(', ')', ', ', '[' and ']', determine if the input string is valid. Brackets must close in the correct order.
4. Maximum Subarray (Kadane's Algorithm)
MediumFind the contiguous subarray within an array which has the largest sum. This is solved efficiently using Kadane's algorithm.
5. Binary Tree Level Order Traversal (BFS)
MediumTraverse a binary tree level by level from left to right using Breadth-First Search (BFS).
6. Longest Substring Without Repeating Characters
MediumFind the length of the longest substring without repeating characters using sliding window technique.
7. Merge Intervals
MediumGiven a collection of intervals, merge all overlapping intervals.
8. Lowest Common Ancestor of Binary Tree
MediumFind the lowest common ancestor (LCA) of two nodes in a binary tree.
9. Course Schedule (Topological Sort / Cycle Detection)
MediumDetermine if you can finish all courses given prerequisites. This is a graph cycle detection problem.
10. LRU Cache Implementation
HardDesign and implement a Least Recently Used (LRU) cache with O(1) time complexity for both get and put operations.
11. Binary Search
EasyImplement binary search to find the index of a target value in a sorted array.
12. Climbing Stairs (Dynamic Programming)
EasyYou're climbing a staircase with n steps. Each time you can climb 1 or 2 steps. How many distinct ways can you climb to the top?
13. Product of Array Except Self
MediumGiven an array, return an array where each element is the product of all elements except itself, without using division and in O(n) time.
14. Kth Largest Element in Array (QuickSelect)
MediumFind the kth largest element in an unsorted array using QuickSelect algorithm.
15. Rotated Sorted Array Search
MediumSearch for a target in a rotated sorted array in O(log n) time.
16. Word Break (Dynamic Programming)
MediumGiven a string s and a dictionary of words, determine if s can be segmented into space-separated sequence of dictionary words.
17. Number of Islands (Graph DFS/BFS)
MediumCount the number of islands in a 2D grid where '1' represents land and '0' represents water.
18. Coin Change (Dynamic Programming)
MediumFind the minimum number of coins needed to make up a given amount using unlimited coins of given denominations.
19. Validate Binary Search Tree
MediumDetermine if a binary tree is a valid Binary Search Tree (BST).
20. Trapping Rain Water
HardGiven an elevation map where the width of each bar is 1, compute how much water can be trapped after raining.
DSA Interview Tips
- ✓ Always clarify input constraints and edge cases before coding
- ✓ Discuss time and space complexity for each approach
- ✓ Start with brute force, then optimize
- ✓ Use meaningful variable names and add comments
- ✓ Test your code with examples, including edge cases
- ✓ Common patterns: Two Pointers, Sliding Window, DFS/BFS, DP, Binary Search
- ✓ Practice on LeetCode, HackerRank, and CodeSignal