Top Interview Problems
These 40 problems appear repeatedly at Google, Meta, Amazon, and Microsoft. They are not cherry-picked for difficulty — they are selected because each one embodies a core pattern that appears in dozens of variants. Solve these deeply (not just "see the solution") and you will be prepared for 80% of what you encounter at top-tier interviews.
Arrays
Problem | Difficulty | Key Insight | Pattern |
|---|---|---|---|
Two Sum (LC 1) | Easy | Store complement in HashMap; O(n) one pass | HashMap lookup |
Best Time to Buy and Sell Stock (LC 121) | Easy | Track running minimum; answer is max spread seen so far | Greedy / Kadane variant |
Contains Duplicate (LC 217) | Easy | HashSet — insert and check simultaneously | HashSet |
Product of Array Except Self (LC 238) | Medium | Left-pass then right-pass; no division needed | Prefix product |
Maximum Subarray (LC 53) | Medium | Kadane's: reset running sum to 0 when it goes negative | Kadane's algorithm |
Maximum Product Subarray (LC 152) | Medium | Track both min and max — negatives can flip to maximum | DP with two running values |
3Sum (LC 15) | Medium | Sort, fix one element, two-pointer scan for pair; skip duplicates | Sort + Two Pointers |
Container With Most Water (LC 11) | Medium | Two pointers; always move the shorter side inward | Two Pointers |
Strings
Problem | Difficulty | Key Insight | Pattern |
|---|---|---|---|
Valid Anagram (LC 242) | Easy | Count char frequencies; two strings are anagrams if counts match | Frequency array |
Valid Palindrome (LC 125) | Easy | Two pointers; skip non-alphanumeric, compare case-insensitively | Two Pointers |
Longest Substring Without Repeating (LC 3) | Medium | Sliding window with last-seen map; jump left pointer on collision | Sliding Window |
Longest Repeating Character Replacement (LC 424) | Medium | Sliding window; window valid when (length - maxFreq) ≤ k | Sliding Window |
Minimum Window Substring (LC 76) | Hard | Sliding window with two frequency maps; shrink left when valid | Sliding Window |
Group Anagrams (LC 49) | Medium | Sort each string as key; or use frequency tuple as key | HashMap grouping |
Encode and Decode Strings (LC 271) | Medium | Length-prefix encoding: "5#hello3#foo" — avoids delimiter ambiguity | Serialization |
Trees
Problem | Difficulty | Key Insight | Pattern |
|---|---|---|---|
Invert Binary Tree (LC 226) | Easy | Swap left and right children recursively at every node | Tree DFS |
Maximum Depth of Binary Tree (LC 104) | Easy | 1 + max(depth(left), depth(right)) | Tree DFS |
Same Tree (LC 100) | Easy | Recursively check val equality and structural equality | Tree DFS |
Validate BST (LC 98) | Medium | Pass (min, max) bounds down; every node must stay within its bound | Tree DFS with bounds |
Lowest Common Ancestor (LC 236) | Medium | If both nodes are in different subtrees, current node is LCA | Tree DFS |
Binary Tree Level Order (LC 102) | Medium | BFS with queue; drain one level per outer loop iteration | Tree BFS |
Serialize and Deserialize Binary Tree (LC 297) | Hard | BFS or preorder DFS; use sentinel for null nodes in serialization | Tree BFS / DFS |
Binary Tree Maximum Path Sum (LC 124) | Hard | At each node: max contribution = val + max(0, left) + max(0, right) | Tree DFS with global max |
Graphs
Problem | Difficulty | Key Insight | Pattern |
|---|---|---|---|
Number of Islands (LC 200) | Medium | DFS/BFS to flood-fill each island; mark visited in-place with "0" | DFS / BFS flood fill |
Clone Graph (LC 133) | Medium | HashMap from original node to clone; DFS/BFS copies edges | DFS with HashMap |
Pacific Atlantic Water Flow (LC 417) | Medium | BFS from ocean borders inward; answer is intersection of both reachable sets | Multi-source BFS |
Course Schedule (LC 207) | Medium | Detect cycle in directed graph — if cycle exists, can't finish all | Topological Sort / DFS |
Rotting Oranges (LC 994) | Medium | Multi-source BFS from all rotten oranges simultaneously | Multi-source BFS |
Word Ladder (LC 127) | Hard | BFS on implicit graph; each word is a node, edges between 1-char-diff words | BFS on word graph |
Alien Dictionary (LC 269) | Hard | Build ordering DAG from adjacent words; topological sort for final order | Topological Sort |
Dynamic Programming
Problem | Difficulty | Key Insight | Pattern |
|---|---|---|---|
Climbing Stairs (LC 70) | Easy | dp[n] = dp[n-1] + dp[n-2] — same as Fibonacci | 1D DP |
House Robber (LC 198) | Medium | dp[i] = max(dp[i-1], dp[i-2] + nums[i]) — take or skip | 1D DP |
Coin Change (LC 322) | Medium | dp[amount] = min coins; for each coin update dp[amount..coin] | Unbounded Knapsack |
Longest Increasing Subsequence (LC 300) | Medium | O(n log n): binary search patience sort for LIS length | Patience Sort / DP |
Unique Paths (LC 62) | Medium | dp[i][j] = dp[i-1][j] + dp[i][j-1]; or C(m+n-2, m-1) | 2D DP / Combinatorics |
Jump Game (LC 55) | Medium | Greedy: track max reachable index; if current > max, stuck | Greedy |
Word Break (LC 139) | Medium | dp[i] = can we partition s[0..i-1]? Check all split points | 1D DP + HashSet |
Edit Distance (LC 72) | Hard | dp[i][j] = min ops to convert s[0..i] to t[0..j]; 3 choices: insert/delete/replace | 2D DP (LCS variant) |
Partition Equal Subset Sum (LC 416) | Medium | Subset sum DP: can we select elements summing to total/2? | 0/1 Knapsack |
Longest Common Subsequence (LC 1143) | Medium | dp[i][j] = LCS of s[0..i-1] and t[0..j-1]; match or take max of skip | 2D DP |
Study Strategy
Solve problems without hints first — struggle for 20-30 minutes before looking
After solving, ask: what is the pattern? Could I recognize this in a disguised form?
Re-solve the same problem 3 days later without looking at your solution
For Hard problems, understand the key insight first, then implement — do not brute-force Hard
Time yourself: aim for Easy in 10 min, Medium in 20 min, Hard in 35 min
Verbal walkthrough: explain your approach aloud before and during coding