Every problem of the NeetCode 150 list, each in its own file, worked extensively: problem statement → brute force → optimal, with code, complexity, and the key insight. The one-line “why this problem is here” and the link to the underlying concept note stay in the tables below; the files are the full solutions.
This complements the concept notes in the folders above (data-structures, algorithms, patterns) — read the concept first to learn the tool, then these to see it applied.
Structure: every solution lives flat in questions/, numbered 001–150 in NeetCode order (so the folder reads in curriculum order without nesting). The topic grouping lives here in this index, not in the folder layout — this README is the map, questions/ is the content.
New to interviews? Read the interview playbook first — the UMPIRE process (reword → clarify → examples → brute-force-then-optimize → code → test) and how to read a problem’s constraints and stated complexity to guess the intended approach before you’ve solved it. The cheat-sheet below is shape → tool; the playbook is how to run the whole interview.
Pattern cheat-sheet — signal → tool
Most of the interview battle is recognizing which of ~18 tools a problem is asking for. This maps the tell-tale signal in a problem to the pattern and its concept note. Read it as “when I see X, reach for Y.”
| When you see… | Reach for | Note |
|---|---|---|
| ”have I seen this?”, count occurrences, dedupe, find a pair by value | Hash map / set — trade space for O(1) lookup | hash-maps |
| sorted array + find a pair/triplet, palindrome, work from both ends | Two pointers converging inward (O(1) space) | two-pointers |
| longest/shortest contiguous substring/subarray meeting a constraint | Sliding window — grow right, shrink left when invalid | sliding-window |
| matched brackets, “most recent unclosed”, next greater/smaller element | Stack / monotonic stack | stacks · monotonic-stack |
| sorted input & search; OR “minimize the max / min feasible speed/capacity” | Binary search — incl. on the answer (monotonic predicate) | modified-binary-search |
| reverse a list, detect a cycle, find the middle / n-th from end | Linked-list pointers — reversal, fast/slow | reversal · fast-slow |
| ”do X at every node, combine children”; OR level-by-level | Tree DFS (return up / carry down) · BFS by level | dfs · bfs |
| prefix / autocomplete queries, search many words in a grid | Trie (+ backtracking for grids) | tries |
| ”k largest/smallest”, “top k”, running median, merge k sorted | Heap (size-k, or two-heap) | heaps · top-k |
| ”generate all subsets / permutations / combinations”, place-then-undo | Backtracking (choose → recurse → un-choose) | backtracking |
| grid connectivity, islands, flood fill, fewest steps on a grid | Graph DFS/BFS (multi-source BFS for nearest) | matrix-traversal · graphs |
| prerequisites, build/task ordering, “can everything be ordered?” | Topological sort (Kahn’s) = cycle detection | topological-sort |
| ”same group?”, dynamic connectivity, cycle in an undirected graph | Union-Find (a failed union = a cycle) | union-find |
| shortest path with weights; OR connect everything at min cost | Dijkstra · MST (Prim/Kruskal); hop-limited → Bellman-Ford | dijkstra · MST |
| ”count the ways”, min/max over choices, overlapping subproblems | Dynamic programming (find the recurrence) | DP |
| a locally-optimal choice that’s provably globally optimal | Greedy (justify with an exchange argument) | greedy |
| overlapping ranges, merge intervals, meeting rooms | Intervals — sort by start/end, then sweep (+ heap) | overlapping-intervals |
| O(1) space demanded, “appears once”, XOR hints, powers of two | Bit manipulation (XOR cancel, n & (n-1)) | bit-manipulation |
rotate/spiral/zero a matrix in place, fast xⁿ, big-int arithmetic | Math & geometry (in-place tricks, binary exponentiation) | math-and-geometry |
Also read the constraints first. The input size n usually leaks the intended complexity — n ≤ 20 hints at exponential backtracking/bitmask, n ≤ ~5000 at O(n²) DP, n ≤ 10⁵ at O(n log n) or O(n), n ≥ 10⁹ at O(log n) or math. See the constraint→complexity heuristic in algorithms.
Progress
- Arrays & Hashing (9)
- Two Pointers (5)
- Sliding Window (6)
- Stack (7)
- Binary Search (7)
- Linked List (11)
- Trees (15)
- Tries (3)
- Heap / Priority Queue (7)
- Backtracking (9)
- Graphs (13)
- Advanced Graphs (6)
- 1-D Dynamic Programming (12)
- 2-D Dynamic Programming (11)
- Greedy (8)
- Intervals (6)
- Math & Geometry (8)
- Bit Manipulation (7)
All 150 solved. ✅
Arrays & Hashing — hash-maps
Trade space for O(1) lookup; recognize when a hash map/set collapses an O(n²) scan to O(n).
| # | Problem | Key idea |
|---|---|---|
| 217 | Contains Duplicate | hash set membership |
| 242 | Valid Anagram | char-count map equality |
| 1 | Two Sum | map value → index; look for the complement |
| 49 | Group Anagrams | key by char-count signature |
| 347 | Top K Frequent Elements | count map + bucket sort |
| 271 | Encode and Decode Strings | length-prefix each string |
| 238 | Product of Array Except Self | prefix × suffix, no division |
| 36 | Valid Sudoku | hash sets per row/col/box |
| 128 | Longest Consecutive Sequence | set; start a run only at its left edge |
Two Pointers — two-pointers
| # | Problem | Key idea |
|---|---|---|
| 125 | Valid Palindrome | pointers in from both ends, skip non-alphanumerics |
| 167 | Two Sum II | inward pointers; move by sum vs target |
| 15 | 3Sum | sort, fix one, two-pointer the rest; skip dupes |
| 11 | Container With Most Water | widest first; move the shorter wall inward |
| 42 | Trapping Rain Water | two pointers tracking left/right max walls |
Sliding Window — sliding-window
| # | Problem | Key idea |
|---|---|---|
| 121 | Best Time to Buy and Sell Stock | track min-so-far; window = buy…sell |
| 3 | Longest Substring Without Repeating Characters | grow; shrink on a repeat |
| 424 | Longest Repeating Character Replacement | valid while (len − maxfreq) ≤ k |
| 567 | Permutation in String | fixed window; compare char counts |
| 76 | Minimum Window Substring | expand to satisfy, contract to minimize |
| 239 | Sliding Window Maximum | monotonic deque of candidate maxima |
Stack — stacks-and-queues
| # | Problem | Key idea |
|---|---|---|
| 20 | Valid Parentheses | push opens, match/pop on closes |
| 155 | Min Stack | pair each value with the min-so-far |
| 150 | Evaluate Reverse Polish Notation | pop operands, push results |
| 22 | Generate Parentheses | backtracking with open/close counts |
| 739 | Daily Temperatures | monotonic stack of indices |
| 853 | Car Fleet | sort by position; monotonic stack of times |
| 84 | Largest Rectangle in Histogram | monotonic stack of increasing heights |
Binary Search — modified-binary-search
| # | Problem | Key idea |
|---|---|---|
| 704 | Binary Search | the baseline half-and-discard |
| 74 | Search a 2D Matrix | treat the grid as one sorted array |
| 875 | Koko Eating Bananas | binary search on the answer |
| 153 | Find Minimum in Rotated Sorted Array | compare mid to right |
| 33 | Search in Rotated Sorted Array | find the sorted half, then bound |
| 981 | Time Based Key-Value Store | binary search over timestamps |
| 4 | Median of Two Sorted Arrays | binary search on the partition |
Linked List — linked-lists
| # | Problem | Key idea |
|---|---|---|
| 206 | Reverse Linked List | iterative pointer flip |
| 21 | Merge Two Sorted Lists | two-pointer merge with a dummy |
| 143 | Reorder List | mid + reverse + interleave |
| 19 | Remove Nth Node From End | two pointers n apart |
| 138 | Copy List with Random Pointer | interleave clones or old→new map |
| 2 | Add Two Numbers | digit-by-digit with carry |
| 141 | Linked List Cycle | Floyd’s fast/slow |
| 287 | Find the Duplicate Number | Floyd’s on value-as-pointer |
| 146 | LRU Cache | hash map + doubly linked list |
| 23 | Merge K Sorted Lists | min-heap of k heads |
| 25 | Reverse Nodes in k-Group | reverse each k-block |
Trees — trees · traversal
| # | Problem | Key idea |
|---|---|---|
| 226 | Invert Binary Tree | swap children recursively |
| 104 | Maximum Depth of Binary Tree | 1 + max(left, right) |
| 543 | Diameter of Binary Tree | max(left height + right height) |
| 110 | Balanced Binary Tree | height check returning −1 on imbalance |
| 100 | Same Tree | structural + value recursion |
| 572 | Subtree of Another Tree | ”same tree” at every node |
| 235 | Lowest Common Ancestor of a BST | descend by BST ordering |
| 102 | Binary Tree Level Order Traversal | BFS by level |
| 199 | Binary Tree Right Side View | BFS; last node per level |
| 1448 | Count Good Nodes in Binary Tree | DFS carrying max-on-path |
| 98 | Validate Binary Search Tree | DFS carrying (min, max) |
| 230 | Kth Smallest Element in a BST | in-order, stop at k |
| 105 | Construct Tree from Preorder & Inorder | root from pre, split via in |
| 124 | Binary Tree Maximum Path Sum | DFS best-arm + global max |
| 297 | Serialize and Deserialize Binary Tree | pre-order with null markers |
Tries — tries
| # | Problem | Key idea |
|---|---|---|
| 208 | Implement Trie (Prefix Tree) | insert / search / startsWith |
| 211 | Design Add and Search Words | wildcard . → branch DFS |
| 212 | Word Search II | one trie + grid backtracking |
Heap / Priority Queue — heaps · top-k
| # | Problem | Key idea |
|---|---|---|
| 703 | Kth Largest Element in a Stream | min-heap of size k |
| 1046 | Last Stone Weight | max-heap, smash two heaviest |
| 973 | K Closest Points to Origin | heap by squared distance |
| 215 | Kth Largest Element in an Array | heap O(n log k) vs Quickselect |
| 621 | Task Scheduler | max-heap by count + cooldown |
| 355 | Design Twitter | k-way merge via heap |
| 295 | Find Median from Data Stream | two heaps |
Backtracking — backtracking
| # | Problem | Key idea |
|---|---|---|
| 78 | Subsets | include/exclude each element |
| 39 | Combination Sum | reuse allowed; recurse on same index |
| 46 | Permutations | swap-in-place or used-set |
| 90 | Subsets II | sort, skip duplicate siblings |
| 40 | Combination Sum II | sort, each once, skip dup siblings |
| 79 | Word Search | grid DFS with visited + undo |
| 131 | Palindrome Partitioning | cut at every palindromic prefix |
| 17 | Letter Combinations of a Phone Number | product over digit→letters |
| 51 | N-Queens | place per row; column/diagonal sets |
Graphs — graphs · matrix-traversal
| # | Problem | Key idea |
|---|---|---|
| 200 | Number of Islands | grid flood fill, count components |
| 133 | Clone Graph | DFS/BFS with old→new map |
| 695 | Max Area of Island | flood fill returning area |
| 417 | Pacific Atlantic Water Flow | reverse-flow BFS from both oceans |
| 130 | Surrounded Regions | mark border-connected regions safe |
| 994 | Rotting Oranges | multi-source BFS by minute |
| 286 | Walls and Gates | multi-source BFS from gates |
| 207 | Course Schedule | topological-sort feasibility |
| 210 | Course Schedule II | topological order itself |
| 684 | Redundant Connection | union-find; first cycle edge |
| 323 | Number of Connected Components | union-find; count roots |
| 261 | Graph Valid Tree | union-find; n−1 edges, no cycle |
| 127 | Word Ladder | BFS over one-letter-change neighbors |
Advanced Graphs — dijkstra · MST · topo-sort
| # | Problem | Key idea |
|---|---|---|
| 332 | Reconstruct Itinerary | Hierholzer’s Eulerian path |
| 1584 | Min Cost to Connect All Points | MST (Prim’s / Kruskal’s) |
| 743 | Network Delay Time | Dijkstra, take the max |
| 778 | Swim in Rising Water | Dijkstra / binary search on max cell |
| 269 | Alien Dictionary | precedence edges → topological sort |
| 787 | Cheapest Flights Within K Stops | Bellman-Ford bounded to k+1 |
1-D Dynamic Programming — dynamic-programming
| # | Problem | Key idea |
|---|---|---|
| 70 | Climbing Stairs | Fibonacci shape |
| 746 | Min Cost Climbing Stairs | min of two prior + cost |
| 198 | House Robber | max(skip, rob + dp[i-2]) |
| 213 | House Robber II | two linear runs (drop first/last) |
| 5 | Longest Palindromic Substring | expand around center |
| 647 | Palindromic Substrings | count center expansions |
| 91 | Decode Ways | 1-digit and valid 2-digit splits |
| 322 | Coin Change | unbounded knapsack |
| 152 | Maximum Product Subarray | track running max and min |
| 139 | Word Break | dp[i] true if a word ends at i |
| 300 | Longest Increasing Subsequence | dp[i]=1+max(dp[j]<); O(n log n) |
| 416 | Partition Equal Subset Sum | subset-sum to total/2 |
2-D Dynamic Programming — dynamic-programming
| # | Problem | Key idea |
|---|---|---|
| 62 | Unique Paths | dp[r][c]=dp[r-1][c]+dp[r][c-1] |
| 1143 | Longest Common Subsequence | match → diagonal+1 |
| 309 | Buy/Sell Stock with Cooldown | hold/sold/rest state machine |
| 518 | Coin Change II | count combinations |
| 494 | Target Sum | ± signs → subset-sum count |
| 97 | Interleaving String | 2-D reachability |
| 329 | Longest Increasing Path in a Matrix | DFS + memo |
| 115 | Distinct Subsequences | match → sum; else carry |
| 72 | Edit Distance | 1+min(insert, delete, replace) |
| 312 | Burst Balloons | interval DP on last balloon |
| 10 | Regular Expression Matching | 2-D with */. transitions |
Greedy — greedy
| # | Problem | Key idea |
|---|---|---|
| 53 | Maximum Subarray | Kadane’s |
| 55 | Jump Game | farthest reachable index |
| 45 | Jump Game II | extend current jump’s range |
| 134 | Gas Station | failing point + 1 if total ≥ 0 |
| 846 | Hand of Straights | count map + take runs from smallest |
| 1899 | Merge Triplets to Form Target | keep triplets never exceeding target |
| 763 | Partition Labels | extend to last index of each char |
| 678 | Valid Parenthesis String | track min/max open count |
Intervals — overlapping-intervals
| # | Problem | Key idea |
|---|---|---|
| 57 | Insert Interval | before / merge / after |
| 56 | Merge Intervals | sort by start, merge touching |
| 435 | Non-overlapping Intervals | sort by end; count removals |
| 252 | Meeting Rooms | sort; any overlap → false |
| 253 | Meeting Rooms II | min-heap of end times |
| 1851 | Minimum Interval to Include Each Query | sort + heap by size |
Math & Geometry — math-and-geometry
| # | Problem | Key idea |
|---|---|---|
| 48 | Rotate Image | transpose + reverse rows |
| 54 | Spiral Matrix | four shrinking boundaries |
| 73 | Set Matrix Zeroes | use row 0 / col 0 as markers |
| 202 | Happy Number | cycle detection |
| 66 | Plus One | grade-school carry |
| 50 | Pow(x, n) | fast exponentiation |
| 43 | Multiply Strings | digit-by-digit multiply |
| 2013 | Detect Squares | point-count hash map |
Bit Manipulation — bit-manipulation
| # | Problem | Key idea |
|---|---|---|
| 136 | Single Number | XOR everything; pairs cancel |
| 191 | Number of 1 Bits | x &= x-1 (Kernighan) |
| 338 | Counting Bits | count[i]=count[i>>1]+(i&1) |
| 190 | Reverse Bits | shift out, shift in, ×32 |
| 268 | Missing Number | XOR indices with values |
| 371 | Sum of Two Integers | XOR + carry loop |
| 7 | Reverse Integer | reverse digits with overflow guard |
Related
- DSA index — the concept notes underneath
- patterns overview — the pattern layer these drill
Software engineering
Infrastructure & security
Computer science
Hardware & engineering