Geeks kepler

50 DSA Interview Questions & Answers 2025 – Google, Amazon, Microsoft Level

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)

  1. Longest Consecutive Sequence → HashSet
  2. Valid Sudoku → 9 row + 9 col + 9 box sets
  3. Combination Sum (Backtracking)
  4. Permutations of array (Backtracking)
  5. Subsets / Power Set (Backtracking or Bit)
  6. N-Queens (Backtracking classic)
  7. Binary Tree Level Order Traversal (BFS)
  8. Binary Tree Maximum Path Sum
  9. Lowest Common Ancestor of BST / Binary Tree
  10. Kth Smallest Element in BST (Inorder)
  11. Serialize and Deserialize Binary Tree
  12. Word Ladder (BFS shortest path)
  13. Min Cost Path in Grid (DP or BFS with cost)
  14. Coin Change (DP – unbounded knapsack)
  15. Longest Increasing Subsequence (DP O(n²) or O(n log n))
  16. Edit Distance (DP classic)
  17. House Robber I & II (DP)
  18. Unique Paths (DP or Math)
  19. Climbing Stairs → Fibonacci DP
  20. Partition Equal Subset Sum (0/1 Knapsack)
  21. Longest Palindromic Substring (DP or Expand Around Center)
  22. Regular Expression Matching (DP hard)
  23. Merge Intervals
  24. Insert Interval
  25. Spiral Matrix
  26. Set Matrix Zeroes (O(1) space)
  27. Product of Array Except Self (Prefix-Suffix)
  28. First Missing Positive (O(1) space – swap)
  29. Find Median from Data Stream (Two Heaps)
  30. Sliding Window Maximum (Deque)

50 DSA Interview Questions & Answers 2025 – Google, Amazon, Microsoft Level

95% of DSA interviews in 2025 revolve around these 50 questions!

DSA Interview 2025
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

Exit mobile version