Skip to content

Problem Bank

This curated list of 76 problems covers the most frequently tested topics and patterns in software engineering interviews. Solving these problems will give you strong coverage of the concepts that appear at Google, Meta, Amazon, Apple, Microsoft, and other top companies.

How to Use This Problem Bank

  1. Work through topics in order — they build on each other
  2. Solve Easy problems first within each topic before attempting Medium
  3. For each problem: read the description, try it yourself for 20-30 minutes, then study the solution
  4. Note the pattern — connecting problems to patterns is more valuable than memorizing solutions
  5. Revisit problems you struggled with after 3 days, then again after 7 days

Difficulty Guide

DifficultyTarget TimeWhat It Tests
Easy10-15 minCore concept, single pattern
Medium20-30 minPattern combination, edge cases, optimization
Hard30-45 minMultiple patterns, complex logic, creative insight

Progress Tracker

TopicTotalEasyMediumHard
Arrays and Hashing9351
Two Pointers5131
Sliding Window4121
Stack4121
Binary Search5131
Linked Lists6231
Trees9342
Graphs7052
Dynamic Programming11263
Backtracking4031
Greedy4130
Intervals3120
Heap / Priority Queue2011
Bit Manipulation2200
Total76184315

Arrays and Hashing

#ProblemDifficultyPatternKey Insight
1Two SumEasyHash MapStore complement in a hash map for O(1) lookup. One-pass: check before inserting.
2Contains DuplicateEasyHash SetInsert into a set; if insertion fails, a duplicate exists. O(n) time, O(n) space.
3Valid AnagramEasyHash Map / SortingCompare character frequency counts. Sorting works in O(n log n); counting in O(n).
4Group AnagramsMediumHash MapUse sorted characters (or character count tuple) as the hash key to group words.
5Top K Frequent ElementsMediumHash Map + HeapCount frequencies with a hash map, then use a min-heap of size k or bucket sort for O(n).
6Product of Array Except SelfMediumPrefix/SuffixBuild prefix products left-to-right, then suffix products right-to-left. Avoids division.
7Encode and Decode StringsMediumString EncodingUse a length-prefixed encoding like “4#word” to handle any character, including delimiters.
8Longest Consecutive SequenceMediumHash SetPut all numbers in a set. For each number that has no predecessor (num-1 not in set), count the streak.
9First Missing PositiveHardIndex as HashPlace each number at its correct index (num at index num-1). Then scan for the first mismatch.

Two Pointers

#ProblemDifficultyPatternKey Insight
10Valid PalindromeEasyTwo Pointers (inward)Compare characters from both ends, skipping non-alphanumeric characters.
11Two Sum II (Sorted)MediumTwo Pointers (inward)Left and right pointers move inward. Sum too small? Move left. Too large? Move right.
123SumMediumSort + Two PointersSort the array. Fix one element, use two pointers for the remaining pair. Skip duplicates carefully.
13Container With Most WaterMediumTwo Pointers (inward)Start at widest container. Move the shorter wall inward since that is the only way to potentially increase area.
14Trapping Rain WaterHardTwo Pointers / StackTrack max-left and max-right as you move inward. Water at each position = min(maxL, maxR) - height.

Sliding Window

#ProblemDifficultyPatternKey Insight
15Best Time to Buy and Sell StockEasySliding Window / KadaneTrack the minimum price so far. At each price, check if selling yields a new max profit.
16Longest Substring Without Repeating CharactersMediumVariable Window + SetExpand right. When a duplicate is found, shrink left until the window is valid again.
17Longest Repeating Character ReplacementMediumVariable Window + CountWindow is valid when window_size - max_frequency <= k. Shrink left when invalid.
18Minimum Window SubstringHardVariable Window + MapExpand right to include all required characters, then shrink left to find the minimum valid window.

Stack

#ProblemDifficultyPatternKey Insight
19Valid ParenthesesEasyStackPush opening brackets. Pop and compare for closing brackets. Stack must be empty at the end.
20Min StackMediumTwo StacksMaintain a parallel stack tracking the minimum at each level. O(1) getMin.
21Daily TemperaturesMediumMonotonic StackMaintain a decreasing stack of indices. When a warmer day is found, pop and calculate distance.
22Largest Rectangle in HistogramHardMonotonic StackMaintain an increasing stack of heights. When a shorter bar is found, calculate areas by popping.

#ProblemDifficultyPatternKey Insight
23Binary SearchEasyStandard Binary SearchClassic left <= right loop. Compare mid with target. Adjust left or right accordingly.
24Search a 2D MatrixMediumBinary SearchTreat the 2D matrix as a flattened 1D array. Convert index with row = mid // cols, col = mid % cols.
25Koko Eating BananasMediumBinary Search on AnswerBinary search on eating speed k from 1 to max(piles). Check if she can finish in h hours at speed k.
26Search in Rotated Sorted ArrayMediumModified Binary SearchDetermine which half is sorted. Check if target lies in the sorted half. Adjust pointers.
27Median of Two Sorted ArraysHardBinary Search on PartitionBinary search on the shorter array. Partition both arrays so left halves contain the smaller elements.

Linked Lists

#ProblemDifficultyPatternKey Insight
28Reverse Linked ListEasyIterative ReversalMaintain three pointers: prev, curr, next. Redirect arrows one by one.
29Merge Two Sorted ListsEasyDummy Head + CompareUse a dummy node to simplify edge cases. Compare heads, attach the smaller one, advance that pointer.
30Linked List CycleMediumFast/Slow PointersFast moves 2 steps, slow moves 1. If they meet, there is a cycle. If fast reaches null, no cycle.
31Reorder ListMediumFind Middle + Reverse + MergeSplit at middle using fast/slow. Reverse the second half. Interleave the two halves.
32Remove Nth Node From EndMediumTwo Pointers with GapAdvance fast pointer n steps ahead. Then move both until fast reaches the end. Slow is at the target.
33Merge K Sorted ListsHardHeap + MergePush the head of each list into a min-heap. Pop the smallest, add its next to the heap.

Trees

#ProblemDifficultyPatternKey Insight
34Invert Binary TreeEasyDFS (Recursive)Swap left and right children at every node, then recurse on both subtrees.
35Maximum Depth of Binary TreeEasyDFSBase case: null node returns 0. Return 1 + max(depth of left, depth of right).
36Same TreeEasyDFS (Simultaneous)Compare values at each node. Recurse on left-left and right-right. Both null = equal, one null = not equal.
37Subtree of Another TreeMediumDFS + Same TreeFor each node in the main tree, check if the subtree rooted there is identical to the target tree.
38Lowest Common Ancestor of BSTMediumBST PropertyIf both values are smaller, go left. Both larger, go right. Otherwise, current node is the LCA.
39Binary Tree Level Order TraversalMediumBFSUse a queue. Process all nodes at current level, then add their children for the next level.
40Validate BSTMediumDFS + RangePass min/max bounds down. Each node must be within its valid range. Update bounds on recursion.
41Binary Tree Maximum Path SumHardDFS + Global MaxAt each node, compute the max “arm” (node + best child). Update global max with node + both arms.
42Serialize and Deserialize Binary TreeHardBFS or Preorder DFSUse preorder with null markers. Serialize: DFS writing values. Deserialize: read values and rebuild.

Graphs

#ProblemDifficultyPatternKey Insight
43Number of IslandsMediumDFS/BFS on GridFor each unvisited land cell, run DFS/BFS to mark the entire island. Count the number of DFS/BFS calls.
44Clone GraphMediumBFS/DFS + Hash MapUse a hash map from original node to clone. BFS/DFS: clone neighbors lazily, linking clones together.
45Pacific Atlantic Water FlowMediumReverse DFS/BFSInstead of flowing from each cell, start BFS from ocean borders. Find cells reachable from both oceans.
46Course ScheduleMediumTopological Sort / DFSModel courses as a directed graph. If a cycle exists (via DFS coloring or topo sort failure), return false.
47Course Schedule IIMediumTopological Sort (Kahn)BFS with in-degree tracking. Process nodes with in-degree 0. If all nodes processed, return the order.
48Word LadderHardBFSEach word is a node. Connect words differing by one letter. BFS from beginWord finds the shortest path.
49Alien DictionaryHardTopological SortCompare adjacent words to extract ordering edges. Run topological sort. Detect cycles for invalid orderings.

Dynamic Programming

#ProblemDifficultyPatternKey Insight
50Climbing StairsEasy1D DP (Fibonacci)dp[i] = dp[i-1] + dp[i-2]. You can reach step i from step i-1 or i-2.
51House RobberEasy1D DPdp[i] = max(dp[i-1], dp[i-2] + nums[i]). At each house, choose to rob it or skip it.
52Coin ChangeMedium1D DP (Unbounded Knapsack)dp[amount] = min coins to make that amount. For each coin, dp[a] = min(dp[a], dp[a-coin] + 1).
53Longest Increasing SubsequenceMedium1D DP / Binary SearchDP: dp[i] = longest ending at i. O(n log n): maintain a tails array and binary search for insertion point.
54Word BreakMedium1D DP + Setdp[i] = true if s[0:i] can be segmented. Check all j < i: dp[j] and s[j:i] in dictionary.
55Unique PathsMedium2D DPdp[i][j] = dp[i-1][j] + dp[i][j-1]. Only move right or down. Can optimize to 1D array.
56Longest Common SubsequenceMedium2D DPIf chars match, dp[i][j] = dp[i-1][j-1] + 1. Else, dp[i][j] = max(dp[i-1][j], dp[i][j-1]).
57Decode WaysMedium1D DPdp[i] = ways to decode s[0:i]. Single digit valid? Add dp[i-1]. Two digits valid? Add dp[i-2].
580/1 KnapsackMedium2D DPdp[i][w] = max value using first i items with capacity w. Include or exclude each item.
59Edit DistanceHard2D DPdp[i][j] = min ops to convert word1[0:i] to word2[0:j]. Insert, delete, or replace are the three choices.
60Longest Palindromic SubstringHard2D DP / Expand Around CenterExpand around each center (single char and between chars). Track the longest found. O(n^2) time, O(1) space.
61Burst BalloonsHardInterval DPdp[l][r] = max coins from popping balloons between l and r. Choose the last balloon to pop in the range.

Backtracking

#ProblemDifficultyPatternKey Insight
62SubsetsMediumBacktrackingAt each element, choose to include or exclude it. Generates all 2^n subsets.
63Combination SumMediumBacktracking + PruningSort candidates. For each candidate, either use it again (allow reuse) or move to next. Prune when sum exceeds target.
64PermutationsMediumBacktrackingAt each position, try every unused element. Swap or use a visited set to track used elements.
65Word SearchHardDFS Backtracking on GridFrom each cell matching the first letter, DFS in 4 directions. Mark cells visited during search, unmark on backtrack.

Greedy

#ProblemDifficultyPatternKey Insight
66Maximum Subarray (Kadane)EasyGreedy / DPAt each element, either extend the current subarray or start a new one. current = max(num, current + num).
67Jump GameMediumGreedyTrack the farthest reachable index. If you reach a position beyond farthest, return false.
68Gas StationMediumGreedyIf total gas >= total cost, a solution exists. Start from the station after the one where running sum goes negative.
69Hand of StraightsMediumGreedy + Hash MapSort cards. For each smallest card, try to form a group of W consecutive. Use a frequency map to check availability.

Intervals

#ProblemDifficultyPatternKey Insight
70Meeting RoomsEasySort + ScanSort by start time. If any interval overlaps with the previous one, return false.
71Merge IntervalsMediumSort + MergeSort by start time. If current overlaps with last merged, extend the end. Otherwise, add a new interval.
72Non-Overlapping IntervalsMediumGreedySort by end time. Greedily keep intervals with earliest end. Count removed overlaps.

Heap / Priority Queue

#ProblemDifficultyPatternKey Insight
73Kth Largest Element in ArrayMediumMin-Heap of Size KMaintain a min-heap of size k. After processing all elements, the heap top is the kth largest. Also solvable with Quickselect in O(n) average.
74Find Median from Data StreamHardTwo HeapsUse a max-heap for the lower half and a min-heap for the upper half. Balance sizes so they differ by at most 1. Median is the top of the larger heap (or average of both tops).

Bit Manipulation

#ProblemDifficultyPatternKey Insight
75Single NumberEasyXORXOR all elements. Pairs cancel out (a ^ a = 0). The remaining value is the unique element.
76Number of 1 BitsEasyBit ClearingUse n & (n-1) to clear the lowest set bit. Count iterations until n becomes 0.

Study Order Recommendation

For maximum efficiency, solve the problems in this order. Each phase builds on the skills developed in the previous one.

Phase 1: Fundamentals (Week 1-2)

Solve problems 1-9 (Arrays and Hashing), 10-14 (Two Pointers), and 15-18 (Sliding Window). These patterns form the foundation and appear in nearly every interview.

Phase 2: Core Data Structures (Week 3-4)

Solve problems 19-22 (Stack), 23-27 (Binary Search), and 28-33 (Linked Lists). These test your ability to use data structures appropriately and implement pointer manipulation.

Phase 3: Trees and Graphs (Week 5-6)

Solve problems 34-42 (Trees) and 43-49 (Graphs). Tree and graph problems are the most frequently tested category at top companies. Master DFS, BFS, and topological sort.

Phase 4: Advanced Patterns (Week 7-8)

Solve problems 50-61 (Dynamic Programming), 62-65 (Backtracking), and 66-76 (Greedy, Intervals, Heap, Bit Manipulation). DP is the hardest category. Start with easy DP problems and work up gradually.


Patterns by Frequency in Interviews

Based on aggregated data from interview reports, here is how often each pattern appears:

PatternFrequencyPriority
Arrays + Hash MapVery HighMust master first
Trees (DFS/BFS)Very HighMust master
Two PointersHighMust master
Sliding WindowHighMust master
Binary SearchHighMust master
Dynamic ProgrammingHighMust master (medium problems at minimum)
GraphsMedium-HighImportant for top companies
StackMediumImportant
Linked ListsMediumImportant
BacktrackingMediumImportant for combinations/permutations
GreedyMediumImportant
HeapMediumFocus on Top-K problems
IntervalsMedium-Low2-3 problems are enough
Bit ManipulationLowKnow the basics
Union-FindLowKnow the template

Next Steps