50 Most Asked DSA Interview Questions & Answers 2025
Google • Amazon • Microsoft • Meta • Goldman Sachs Level
1. Two Sum (LeetCode #1) – Classic HashMap
Answer: Use a hashmap to store (target – nums[i]) → index. While looping, check if current number exists in map. If yes → return both indices.
Time: O(n) | Space: O(n)
2. Best Time to Buy and Sell Stock
Answer: Keep track of minimum price seen so far. At each day, calculate profit = prices[i] – minPrice. Update global maxProfit.
O(n) time – One pass
3. Contains Duplicate
Answer: Use a Set. Loop through array → if element already in set → return true. Else add it.
4. Reverse a Linked List
Answer: Three pointers: prev = null, curr = head, next = null. While curr != null → next = curr.next → curr.next = prev → prev = curr → curr = next.
5. Merge Two Sorted Lists
Answer: Create dummy node. Use a pointer ‘tail’. Compare both heads → attach smaller one → move that head → move tail. At end, attach remaining list.
6. Valid Parentheses
Answer: Classic Stack problem. Push opening brackets. On closing → pop and check if matches. At end stack should be empty.
7. Maximum Subarray (Kadane’s Algorithm)
Answer: Keep currentSum. If currentSum becomes negative → reset to 0 (or current element). Track maxSum.
8. Invert/Flip Binary Tree
Answer: Simple recursion: swap left and right child → recurse on both children.
9. Valid Palindrome (ignore non-alphanumeric)
Answer: Two pointers from start and end. Skip non-alphanumeric. Compare lowercase chars.
10. Longest Substring Without Repeating Characters
Answer: Sliding window + HashMap (char → latest index). When repeat found → move left to (lastIndex + 1).
11. 3Sum → Find all unique triplets that sum to zero
Answer: Sort array → fix first element → use two pointers on remaining. Skip duplicates to avoid duplicate triplets.
12. Container With Most Water
Answer: Two pointers from ends. Area = min(height[left], height[right]) * distance. Move the shorter pointer inward.
13. Trapping Rain Water
Answer: Two pointers. Keep leftMax and rightMax. Water trapped at each bar = min(leftMax, rightMax) – height[i]
14. Number of Islands (DFS/BFS on Grid)
Answer: Loop through grid → when see ‘1’ → DFS/BFS to mark entire island → increment count.
15. Clone Graph (Deep Copy)
Answer: Use HashMap (oldNode → newNode). DFS/BFS → create node if not in map → copy neighbors.
16. Course Schedule (Cycle Detection in Directed Graph)
Answer: Topological sort using Kahn’s algorithm (indegree) or DFS with recursion stack.
17. Implement Trie (Prefix Tree)
Answer: Node has children[26] and isEnd boolean. Insert → traverse/create nodes. Search → traverse till end.
18. Word Search in 2D Board
Answer: DFS from every cell. Mark visited (use ‘#’ temporarily). Backtrack.
19. LRU Cache
Answer: HashMap + Doubly Linked List. get() → move to front. put() → if full, remove tail.
20. Merge K Sorted Lists
Answer: Min-Heap (PriorityQueue) → insert all heads → keep extracting min and attaching next.
21–50 Must-Know DSA Questions (With Real Interview Answers)
- Longest Consecutive Sequence → HashSet
- Valid Sudoku → 9 row + 9 col + 9 box sets
- Combination Sum (Backtracking)
- Permutations of array (Backtracking)
- Subsets / Power Set (Backtracking or Bit)
- N-Queens (Backtracking classic)
- Binary Tree Level Order Traversal (BFS)
- Binary Tree Maximum Path Sum
- Lowest Common Ancestor of BST / Binary Tree
- Kth Smallest Element in BST (Inorder)
- Serialize and Deserialize Binary Tree
- Word Ladder (BFS shortest path)
- Min Cost Path in Grid (DP or BFS with cost)
- Coin Change (DP – unbounded knapsack)
- Longest Increasing Subsequence (DP O(n²) or O(n log n))
- Edit Distance (DP classic)
- House Robber I & II (DP)
- Unique Paths (DP or Math)
- Climbing Stairs → Fibonacci DP
- Partition Equal Subset Sum (0/1 Knapsack)
- Longest Palindromic Substring (DP or Expand Around Center)
- Regular Expression Matching (DP hard)
- Merge Intervals
- Insert Interval
- Spiral Matrix
- Set Matrix Zeroes (O(1) space)
- Product of Array Except Self (Prefix-Suffix)
- First Missing Positive (O(1) space – swap)
- Find Median from Data Stream (Two Heaps)
- Sliding Window Maximum (Deque)

95% of DSA interviews in 2025 revolve around these 50 questions!
LeetCode Top 50
Google Interview Questions
Amazon DSA Questions
Two Pointers
Sliding Window
HashMap Tricks
Tree BFS DFS
Dynamic Programming
Graph Algorithms
Backtracking
Virat Kohli and Rohit Sharma’s ODI Future: BCCI VP Rajiv Shukla Slams Farewell Rumors
