Problems
315 problems in NeetCode order, each with its pattern and the one-line insight that unlocks it. Work them top to bottom. The order is the curriculum.
- 3easy
store value→index; check complement before inserting
Arrays & Hashing · hash map
- 4mediumGroup Anagramsblind75
key = sorted string, or a 26-length count tuple for O(n·k)
Arrays & Hashing · hash + canonical key
- 5mediumTop K Frequent Elementsblind75
bucket by frequency → O(n), beats the heap's O(n log k)
Arrays & Hashing · heap / bucket
- 6medium
length-prefix each string (4#word); delimiters alone are ambiguous
Arrays & Hashing · serialization
- 7mediumProduct of Array Except Selfblind75
left pass then right pass, O(1) extra space
Arrays & Hashing · prefix/suffix
- 9mediumLongest Consecutive Sequenceblind75
only start counting from x where x-1 isn't in the set
Arrays & Hashing · hash set
- 11medium
- 12medium
fix one anchor; dedup twice (anchors and after a hit)
Two Pointers · sort + two pointers
- 13mediumContainer With Most Waterblind75
always move the shorter line — moving the taller can't help
Two Pointers · converging greedy
- 14hardTrapping Rain Waterblind75
water at i = min(left_max, right_max) - h[i]; advance the smaller side
Two Pointers · two pointers
- 15easy
track the min so far; profit = price − min
Sliding Window · running min
- 16medium
last-seen index map; guard last[c] >= left
Sliding Window · variable window
- 17medium
valid iff window_len - max_freq <= k
Sliding Window · variable window
- 18medium
- 19hard
formed/required counters make validity O(1)
Sliding Window · variable window
- 20hard
deque of indices, values decreasing; front is the max
Sliding Window · monotonic deque
- 23medium
- 25medium
- 27hard
increasing stack of (start_index, height), then drain
Stack · monotonic stack
- 29medium
- 30medium
monotonic: if speed k works, every speed > k works
Binary Search · search the answer
- 31medium
compare nums[mid] to nums[hi], never to nums[lo]
Binary Search · modified BS
- 32medium
one half is always sorted — find it, then test containment
Binary Search · modified BS
- 33medium
- 34hard
binary search the split point of the smaller array
Binary Search · BS on partition
- 35easy
prev / curr / next, 4 lines — memorize
Linked List · pointer reversal
- 38mediumRemove Nth Node From Endblind75
fast leads slow by n; dummy head handles head removal
Linked List · gap pointers
- 39medium
- 42medium
- 43medium
sentinel head/tail; nodes must store their key for eviction
Linked List · hashmap + DLL
- 44hard
- 45hard
count k ahead first; reverse the block; reconnect
Linked List · pointer surgery
- 52medium
walk down while both targets are on the same side
Trees · BST property
- 53medium
- 56medium
- 57medium
- 58medium
index map for O(1) root lookup → O(n)
Trees · divide & conquer
- 59hardBinary Tree Maximum Path Sumblind75
clamp negative branches to 0; return one side only
Trees · postorder
- 60hard
- 63hard
- 64easy
- 66medium
- 67medium
heap O(n log k); quickselect O(n) average
Heap / Priority Queue · heap / quickselect
- 68medium
most frequent task first; or the closed-form gap formula
Heap / Priority Queue · greedy + heap
- 70hardFind Median from Data Streamblind75
max-heap low half, min-heap high half, rebalance ritual
Heap / Priority Queue · two heaps
- 72medium
- 73medium
- 74medium
- 75medium
- 77mediumPalindrome Partitioningblind75
try each prefix; recurse only if it's a palindrome
Backtracking · backtracking
- 78medium
digit→letters map, recurse by index
Backtracking · backtracking
- 80medium
- 83medium
seed the queue with every gate
Graphs · multi-source BFS
- 85mediumPacific Atlantic Water Flowblind75
flow outward from each ocean, then intersect
Graphs · reverse BFS/DFS
- 90medium
- 93hard
Eulerian path; append on dead-end, reverse at the end
Advanced Graphs · Hierholzer's
- 96hard
- 97hard
derive edges from the first differing char of adjacent words
Advanced Graphs · topological sort
- 98medium
exactly k+1 rounds; relax from a snapshot
Advanced Graphs · Bellman-Ford
- 100easy
- 102mediumHouse Robber IIblind75
circular → run linear on nums[:-1] and nums[1:]
1-D Dynamic Programming · linear DP ×2
- 103medium
2n−1 centers, O(1) space, beats the DP
1-D Dynamic Programming · expand around center
- 104mediumPalindromic Substringsblind75
same loop, count instead of measure
1-D Dynamic Programming · expand around center
- 105mediumDecode Waysblind75
add one-digit and two-digit options; guard leading '0'
1-D Dynamic Programming · linear DP
- 106medium
dp[0]=0, minimize; unreachable stays inf
1-D Dynamic Programming · unbounded knapsack
- 107mediumMaximum Product Subarrayblind75
track min and max — a negative flips them
1-D Dynamic Programming · linear DP
- 108mediumWord Breakblind75
dp[i] true if some dp[j] true and s[j:i] is a word
1-D Dynamic Programming · segmentation DP
- 109medium
dp[i] = LIS ending at i; then bisect for O(n log n)
1-D Dynamic Programming · LIS
- 110mediumPartition Equal Subset Sumblind75
reachable-sum set; odd total → immediate False
1-D Dynamic Programming · 0/1 knapsack
- 112mediumLongest Common Subsequenceblind75
match → diagonal+1; else max of the two neighbors
2-D Dynamic Programming · two-sequence
- 113medium
three states: hold, sold, rest
2-D Dynamic Programming · state machine
- 114medium
coin loop outside counts combinations, not permutations
2-D Dynamic Programming · unbounded knapsack
- 116medium
dp[i][j]: can s3[:i+j] be formed from s1[:i] + s2[:j]
2-D Dynamic Programming · two-sequence
- 117hard
DAG by strict increase → no visited set needed
2-D Dynamic Programming · DFS + memo
- 118hard
match → dp[i-1][j-1] + dp[i-1][j]; else dp[i-1][j]
2-D Dynamic Programming · two-sequence
- 119medium
three-way min: replace, delete, insert
2-D Dynamic Programming · two-sequence
- 121hard
→ zero occurrences, or one more if chars match
2-D Dynamic Programming · two-sequence
- 122medium
- 127medium
ignore any triplet exceeding the target in any position
Greedy · greedy filter
- 130mediumInsert Intervalblind75
three phases: before / absorb / after — no sort needed
Intervals · interval merge
- 131medium
- 132mediumNon-overlapping Intervalsblind75
interval scheduling — earliest end leaves the most room
Intervals · sort by end
- 134medium
min-heap of end times, or separate sorted start/end arrays
Intervals · sweep / heap
- 135hard
sort queries, push intervals as they become active
Intervals · sort + heap
- 137medium
- 138mediumSet Matrix Zeroesblind75
use row 0 / col 0 as markers, then fill backward
Math & Geometry · matrix, O(1) space
- 143medium
count points; for each diagonal partner, multiply counts
Math & Geometry · hash counting
- 149mediumSum of Two Integersblind75
XOR = sum without carry; (a&b)<<1 = carry; loop
Bit Manipulation · bit arithmetic
- —medium
union by shared email, group by root
Very frequently asked (do all of these) 🔥 · union-find
- —medium
convert the tree into a graph
Trees & Tries, extended · build parent links + BFS
- —medium
- —medium
push signed terms; handle and / immediately
Very frequently asked (do all of these) 🔥 · stack
- —medium
take every upward step: sum of all positive deltas
Arrays & Hashing · greedy
- —hard
- —easy
go left, pop, go right
Very frequently asked (do all of these) 🔥 · stack
- —easy
- —medium
track a column index per node
Trees & Tries, extended · BFS + column map
- —medium
reverse alternate levels
Very frequently asked (do all of these) 🔥 · BFS
- —medium
the answer is the shared high-bit prefix of left and right
Bit Manipulation · common prefix
- —medium
pair the lightest with the heaviest if they fit; else the heaviest goes alone
Two Pointers · sort + converge
- —hard
independently order rows and columns, then place
Advanced Graphs · topological sort ×2
- —medium
barriers, resource counting
Concurrency (Amazon, some backend loops) · Concurrency (Amazon, some backend loops)
- —medium
same shape as Koko
Very frequently asked (do all of these) 🔥 · BS on the answer
- —medium
amount loop outside → counts permutations (contrast with Coin Change II)
1-D Dynamic Programming · unbounded knapsack
- —medium
if the quadrant is uniform it's a leaf, else recurse into four
Trees · divide & conquer
- —easy
keep a set of the last k elements; evict as you slide
Sliding Window · window + set
- —medium
push counts and partial strings on [
Very frequently asked (do all of these) 🔥 · two stacks
- —medium
- —medium
two children → replace with the inorder successor
Trees & Tries, extended · BST surgery
- —medium
fixed array with wraparound
Design / OOP-flavored · Design / OOP-flavored
- —easy
- —medium
- —hard
cache the top-3 at each trie node
Trees & Tries, extended · trie + heap
- —medium
row/col/diagonal counters, O(1) per move
Design / OOP-flavored · Design / OOP-flavored
- —medium
in-progress trips + route totals
Very frequently asked (do all of these) 🔥 · two hash maps
- —medium
deadlock avoidance via lock ordering
Concurrency (Amazon, some backend loops) · Concurrency (Amazon, some backend loops)
- —medium
- —medium
edge weight = the ratio; multiply along the path
Graphs, extended · weighted graph DFS
- —medium
dp[i] = min extra chars from i; walk the trie forward from each index
Tries · trie + DP
- —medium
compare count arrays
Very frequently asked (do all of these) 🔥 · fixed window
- —hard
critical = MST weight rises without it; pseudo = forcing it in keeps the weight
Advanced Graphs · Kruskal ×3
- —medium
- —hard
- —medium
search for the best left boundary in [0, n-k]
Sliding Window · binary search the window
- —medium
move toward the higher neighbor
Very frequently asked (do all of these) 🔥 · BS without sorting
- —medium
build right-skewed, prev pointer
Very frequently asked (do all of these) 🔥 · reverse postorder
- —easy
the answer exists iff a+b == b+a; length is gcd(len(a), len(b))
Math & Geometry · gcd
- —hard
union each number with each of its prime factors; connected ⟺ traversable
Advanced Graphs · union-find over prime factors
- —easy
amortized O(1) via lazy transfer
Very frequently asked (do all of these) 🔥 · two stacks
- —easy
rotate after each push
Very frequently asked (do all of these) 🔥 · one queue
- —medium
swap-with-last on removal
Very frequently asked (do all of these) 🔥 · array + index map
- —medium
splice a node between each adjacent pair
Math & Geometry · traversal + gcd
- —medium
dp[n] = max(i dp[n-i], i (n-i)); the math answer is "use as many 3s as possible"
1-D Dynamic Programming · linear DP
- —medium
track the furthest reachable index and a window of valid launch points
Greedy · BFS / sliding window
- —medium
binary search the value, count elements ≤ mid
Very frequently asked (do all of these) 🔥 · heap / BS on value
- —mediumLCA of a Binary Treeblind75
found in both subtrees → this node is the LCA
Trees & Tries, extended · postorder
- —easy
- —hard
two maps + frequency buckets — the LRU follow-up
Design / OOP-flavored · Design / OOP-flavored
- —easy
- —medium
take the most frequent letter unless it would make three in a row, then take the second
Heap / Priority Queue · greedy + max-heap
- —medium
LCS of s and s[::-1]
Very frequently asked (do all of these) 🔥 · 2-D DP
- —medium
shrink while len(window) > k
Very frequently asked (do all of these) 🔥 · sliding window
- —medium
- —easy
candidate + count; the majority survives cancellation
Very frequently asked (do all of these) 🔥 · Boyer-Moore
- —medium
at most two elements can exceed n/3, so track two candidates
Arrays & Hashing · Boyer-Moore ×2
- —medium
4 buckets to a fixed target; sort descending to prune hard
Backtracking · bitmask / backtracking
- —hard
freq[x] plus group[f] = a stack of values seen f times
Stack · stacks by frequency
- —medium
answer = max(normal Kadane, total − min subarray); guard the all-negative case
Greedy · Kadane ×2
- —medium
- —medium
greedily walk the opposite bit at each level
Trees & Tries, extended · bitwise trie
- —hard
one heap of free rooms by index, one of busy rooms by end time
Intervals · two heaps
- —easy
fill from the end to avoid overwriting
Very frequently asked (do all of these) 🔥 · two pointers backward
- —medium
keep n's bits in the positions where x has zeros
Bit Manipulation · bit construction
- —medium
- —medium
shrink while sum >= target
Very frequently asked (do all of these) 🔥 · sliding window
- —easy
- —easy
- —hard
identical to N-Queens, return only the count — no board needed
Backtracking · backtracking
- —easy
- —medium
- —medium
count components in an adjacency matrix
Very frequently asked (do all of these) 🔥 · union-find
- —medium
maximize the product instead of minimizing a sum
Graphs, extended · Dijkstra variant
- —medium
minimise the largest single step, not the sum
Advanced Graphs · Dijkstra on max-edge
- —medium
use the already-linked level above
Very frequently asked (do all of these) 🔥 · BFS / level links
- —medium
two semaphores ping-ponging
Concurrency (Amazon, some backend loops) · Concurrency (Amazon, some backend loops)
- —easy
semaphores / events
Concurrency (Amazon, some backend loops) · Concurrency (Amazon, some backend loops)
- —medium
binary search the cumulative array
Very frequently asked (do all of these) 🔥 · prefix + bisect
- —medium
pre[r][c] = sum of the rectangle from origin; inclusion–exclusion for a query
Arrays & Hashing · 2-D prefix sum
- —medium
find the two swapped nodes in the sorted sequence
Trees & Tries, extended · inorder
- —easy
write index trails read
Very frequently asked (do all of these) 🔥 · read/write pointers
- —medium
pop larger digits while budget remains
Very frequently asked (do all of these) 🔥 · monotonic stack
- —medium
dummy head, walk to left-1, reverse right-left nodes by head-insertion
Linked List · pointer surgery
- —easy
add each value; subtract twice when a smaller numeral precedes a larger
Math & Geometry · parsing
- —medium
- —medium
start top-right; move left or down
Very frequently asked (do all of these) 🔥 · staircase
- —medium
duplicates break the "which half is sorted" test; shrink lo/hi when nums[lo]==nums[mid]==nums[hi] → O(n) worst case
Binary Search · modified BS
- —hard
preorder + child counts
Design / OOP-flavored · Design / OOP-flavored
- —medium
sort by enqueue time; heap of available tasks by (duration, index); jump the clock when idle
Heap / Priority Queue · sort + heap
- —medium
- —medium
low/mid/high partition in one pass
Very frequently asked (do all of these) 🔥 · three pointers
- —hard
feasibility check = greedy chunking
Very frequently asked (do all of these) 🔥 · BS on the answer
- —hard
- —medium
seed {0: 1}; count running - k
Very frequently asked (do all of these) 🔥 · prefix + hash
- —easy
or the O(n) math: every bit appears in exactly half the subsets
Backtracking · subsets
- —easy
compare left.left with right.right
Very frequently asked (do all of these) 🔥 · parallel recursion
- —easy
list(zip(matrix)) — note it handles non-square, unlike an in-place swap
Math & Geometry · matrix
- —medium
track the closest sum seen
Very frequently asked (do all of these) 🔥 · two pointers
- —easy
- —medium
thread pool + a shared visited set with a lock
Concurrency (Amazon, some backend loops) · Concurrency (Amazon, some backend loops)
- —hard
return all segmentations; memoise by start index or it explodes
Backtracking · backtracking + memo