50
Problems
14
Easy
24
Medium
12
Hard
22
Lectures
How to use this page:
Problems are grouped by the exact lecture that teaches what you need to solve them.
The small tag is a one-word nudge toward the key idea — no hints about the solution.
Collapsed "Extra" sections contain closely related problems that don't perfectly match a single lecture.
Click any row to open on LeetCode.
01Asymptotic Analysis & Sorting
Big-O / Ω / Θ · Insertion Sort · Loop invariants · Comparison-based lower bound
L1
Runtime Review & Asymptotic Notation
Big-O, Ω, Θ — expressing and comparing growth rates
#1
runtime tradeoffEasy↗
#217
O(·) comparisonEasy↗
#215
runtime analysisMedium↗
Two Sum
Can you beat O(n²)? Trade space for time and state the exact complexity.
Contains Duplicate
Multiple approaches — compare their exact asymptotic cost.
Kth Largest Element in an Array
Several approaches exist — state and compare the runtime of each one.
L2
Insertion Sort, Loop Invariants & Sorting Lower Bound
Correctness via loop invariants · Ω(n log n) comparison lower bound via decision
trees
#147
loop invariantMedium↗
#75
loop invariantMedium↗
#912
comparison sortMedium↗
Insertion Sort List
Implement insertion sort on a linked list — maintain and state the exact invariant
from lecture.
Sort Colors
Single-pass Dutch partition — write down a loop invariant that guarantees
correctness.
Sort an Array
Implement any O(n log n) comparison sort from scratch — why can't you do better?
02Graphs — DFS, BFS & Topological Sort
Graph ADT · DFS pre/post-order & edge types · Topological ordering · BFS layers ·
Bipartiteness
L3
Abstract Data Types, Graphs & DFS Introduction
Adjacency list representation · Stack-based DFS · Visited array
#200
DFS / componentsMedium↗
#695
DFSMedium↗
#133
DFS + visited mapMedium↗
#1971
connectivity / BFS / DFSEasy↗
Number of Islands
DFS + visited array from scratch — mirrors the lecture pseudocode.
Max Area of Island
DFS while accumulating a value on the call stack — same traversal, richer
bookkeeping.
Clone Graph
DFS with a map as your visited structure — almost exactly the lecture pseudocode.
Find if Path Exists
BFS/DFS in its simplest form — checking connectivity between two nodes.
L4
DFS — Pre/Post-order & Topological Sort
Timestamps · Tree / back / forward / cross edges · DAG ↔ no back edges · Topo sort
via decreasing post-order
L5
Topological Sort (continued) & BFS
BFS layer structure · BFS = shortest path in unweighted graphs · Bipartite testing
via 2-coloring
#210
topological orderingMedium↗
#994
BFS layersMedium↗
#785
BFS 2-colouringMedium↗
#127
unweighted shortest pathHard↗
#1203
nested topo sortHard↗
Course Schedule II
Output the actual topological order — Kahn's BFS or DFS post-order both work.
Rotting Oranges
Multi-source BFS — each orange is at most one layer beyond its rotting neighbour.
Is Graph Bipartite?
BFS 2-coloring — the exact algorithm proven in L5.
Word Ladder
BFS on an implicit graph — shortest path by number of edges, not weights.
Sort Items by Groups
Hierarchical topological sort — sort the groups first, then sort items within each group.
03Greedy Algorithms
Dijkstra · Greedy stays ahead · Interval scheduling · Optimal caching · Greedy exchange
· Minimising lateness
L6
Shortest Path & Greedy Stays Ahead
Dijkstra's algorithm · "Greedy stays ahead" proof technique
L7
Dijkstra Correctness & Interval Scheduling
Full greedy-stays-ahead proof for Dijkstra · Interval scheduling maximisation
(earliest-finish-time rule)
#1631
Dijkstra variantMedium↗
#1514
Dijkstra generalisedMedium↗
#435
interval schedulingMedium↗
#452
interval coveringMedium↗
Path with Minimum Effort
Dijkstra with a different edge cost — the stays-ahead argument still applies.
Path with Maximum Probability
Dijkstra maximising product of edge weights — same proof skeleton, opposite
direction.
Non-overlapping Intervals
Maximise compatible tasks — earliest finish time rule from L7.
Minimum Number of Arrows to Burst Balloons
Minimum covers of overlapping intervals — greedy on earliest end point.
L8
Optimal Caching & Greedy Exchange Argument
Farthest-in-future eviction · Exchange argument: transform any solution into the
greedy one without increasing cost
#146
caching policyMedium↗
#2037
exchange argumentEasy↗
#2144
greedy exchangeEasy↗
LRU Cache
LRU is the practical proxy for Farthest-in-Future — implement it and think about the
gap.
Minimum Moves to Seat Everyone
An exchange argument shows sorting both lists and pairing them is optimal.
Minimum Cost of Buying Candies with Discount
Prove by exchange that you should always give away the cheapest possible free candy.
L9
Scheduling to Minimise Lateness
Earliest-deadline-first rule · Exchange argument: swapping adjacent inverted jobs
monotonically reduces max lateness
Extra — Greedy (good problems, but broader than a single lecture)
▾
These require the full greedy toolkit (Dijkstra + exchanges + scheduling) or blend
techniques from multiple lectures.
04Divide & Conquer
MergeSort + strong induction · Master Theorem · Closest pair of points · Karatsuba /
Strassen
L10
MergeSort & Solving Recurrences
Divide → Conquer → Combine · T(n) = 2T(n/2)+O(n) · Master Theorem (3 cases)
#148
merge sortMedium↗
#53
D&CMedium↗
#23
D&C mergeHard↗
Sort List
MergeSort on a linked list — implement the recurrence T(n) = 2T(n/2) + O(n) exactly.
Maximum Subarray
D&C: answer is in the left half, right half, or crosses the midpoint — same
recurrence as MergeSort.
Merge K Sorted Lists
Pair-and-merge D&C — write the recurrence and apply the Master Theorem.
L11
Closest Pair of Points
Split, conquer each half, combine across the strip — O(n log n) from an O(n²)
baseline
L12
Integer & Matrix Multiplication — Karatsuba & Strassen
Karatsuba: T(n)=3T(n/2)+O(n) · Strassen: T(n)=7T(n/2)+O(n²) · Beating the
"obvious" lower bound
Extra — Divide & Conquer (broader than Karatsuba/Strassen)
▾
Great D&C problems, but this one is really about binary search rather than
integer/matrix multiplication.
05Dynamic Programming
Weighted interval scheduling · 0/1 Knapsack · Segmented least squares · Bellman-Ford
shortest paths
L13
DP I — Weighted Interval Scheduling
OPT(j) = max(v_j + OPT(p(j)), OPT(j−1)) · Memoisation vs bottom-up · Backtracking
the solution
#198
OPT(j) recurrenceMedium↗
#740
weighted IS reductionMedium↗
#1235
weighted IS — exact matchHard↗
House Robber
"Include this house or skip to the previous compatible one" — the weighted IS
recurrence in disguise.
Delete and Earn
Reduce to House Robber by reformulating compatibility — a clean reduction exercise.
Maximum Profit in Job Scheduling
This is the exact weighted interval scheduling problem from L13 — sort by finish
time, binary search for p(j).
L14
DP II — Knapsack
OPT(i,W) — 2D DP table · "Take item i or don't" · Pseudopolynomial runtime
#322
knapsack (unbounded)Medium↗
#416
0/1 knapsack — exactMedium↗
#474
2D knapsackMedium↗
#494
knapsack countingMedium↗
Coin Change
Unbounded knapsack — items can be reused. Define OPT(amount) and fill the table.
Partition Equal Subset Sum
0/1 Knapsack — can you fill capacity exactly W/2? Direct application of OPT(i,W).
Ones and Zeroes
Two-dimensional capacity — generalise OPT(i,W) to OPT(i,m,n).
Target Sum
Count the number of +/− assignments hitting the target — knapsack counting, not
maximising.
L15
DP III — Segmented Least Squares
OPT(j) = min_{i≤j} {e(i,j) + c + OPT(i−1)} · Partition a sequence minimising cost
+ segment penalty
#1105
segmented LS — directMedium↗
#1547
interval / segment DPHard↗
Filling Bookcase Shelves
Partition books into shelves — OPT(j) = min over split point i of {shelf_cost(i..j)
+ OPT(i−1)}.
Minimum Cost to Cut a Stick
Interval DP with cost depending on segment size — same partition-into-segments
flavour.
L16
DP IV — Shortest Paths & Bellman-Ford
OPT(v,i) = shortest path with ≤i edges · Negative cycle detection (extra column
trick) · O(nm) runtime
#787
Bellman-Ford — exactMedium↗
#1334
all-pairs SPMedium↗
Cheapest Flights Within K Stops
Bellman-Ford with at most K+1 edges — compute OPT(dst, K+1) by running K+1
relaxation rounds.
Find the City with Smallest Reachable Cities
All-pairs shortest paths — run Bellman-Ford from each source, or use the
Floyd-Warshall 3D DP.
Extra — Dynamic Programming (classic DP problems not tied to a specific lecture's algorithm)
▾
These are essential DP patterns but don't map directly to a specific algorithm
(Knapsack/Segmented LS/Bellman-Ford). Work on them after finishing L13–16.
#300
sequence DPMedium↗
#72
2D string DPMedium↗
Longest Increasing Subsequence
OPT(i) = 1 + max OPT(j) for j<i with A[j]<A[i] — a canonical sequence DP to
know cold.
Edit Distance
2D DP on strings — OPT(i,j) = min edits to align first i of s1 with first j of s2.
Classic after Bellman-Ford solidifies 2D DP thinking.
06NP-Completeness & Reductions
3-SAT · Independent Set · 3-SAT ≤_P Independent Set · P vs NP · Certificate
verification
L17
NP-Completeness, Independent Set & P vs NP
Reductions · 3-SAT is NP-complete · 3-SAT ≤_P Independent Set · Verifying vs.
solving
#990
structured SATMedium↗
#698
NP-hard in generalMedium↗
#1349
ind. set (structured)Hard↗
#140
structure → tractabilityHard↗
Satisfiability of Equality Equations
A structured, polynomial-time solvable form of satisfiability — think about why this
is tractable while 3-SAT is not.
Partition to K Equal Sum Subsets
NP-hard in general (bin packing reduction) — yet tractable here via backtracking.
What structure makes this feasible?
Maximum Students Taking Exam
Independent set on a grid — NP-hard on general graphs, polynomial here due to row
structure (bitmask DP).
Word Break II
Looks exponential but DP makes it polynomial — contrast with why general SAT
enumeration cannot do this.
07Linear Programming, Game Theory & Online Learning
LP formulations · LP duality · Zero-sum games · Minimax theorem · MWU / Regret
L20–21
LP Duality & The Minimax Theorem
Weak/strong duality · Complementary slackness · Zero-sum games · Minimax = maximin
via LP duality
#292
zero-sum gameEasy↗
#486
minimaxMedium↗
#877
game theoryMedium↗
#375
minimax / LP dualMedium↗
#714
online decision-makingMedium↗
Nim Game
The simplest zero-sum game — pure optimal strategy, verify it fits the Minimax
Theorem.
Predict the Winner
Two-player zero-sum minimax — the Minimax Theorem guarantees an optimal strategy
exists.
Stone Game
Is there a dominant pure strategy, or must you reason about minimax?
Guess Number Higher or Lower II
Minimise worst-case cost — adversary picks the answer, you minimise. Pure minimax /
LP dual flavour.
Best Time to Buy and Sell Stock with Transaction Fee
Online decision at each time step — think about what "regret" means in this setting.
Beyond the Curriculum
not in DS 320
Important techniques that DS 320 doesn't cover, but that are foundational for algorithm design
more broadly and extremely common in interviews and competitive programming. These complement what you've
learned — treat them as electives after finishing the course material.
Union-Find (Disjoint Set Union)
Near-O(1) amortised connectivity queries — powers Kruskal's MST and many graph
problems
#547
DSU basicsMedium↗
#684
DSU cycle detectionMedium↗
#721
DSU on stringsMedium↗
Number of Provinces
Connected components — implement DSU with union by rank and path compression.
Redundant Connection
Find the edge that creates a cycle — the union operation tells you when two nodes
are already connected.
Accounts Merge
Union accounts sharing an email — DSU on strings.
Monotonic Stack / Queue
O(n) answers to "next greater element" and sliding-window extrema queries
#739
monotonic stackMedium↗
#84
monotonic stackHard↗
#239
monotonic dequeHard↗
Daily Temperatures
Next warmer day for each entry — the classic monotonic stack starter.
Largest Rectangle in Histogram
Maintain a stack of "active" bars — the hardest classic monotonic stack problem.
Sliding Window Maximum
Monotonic deque for max in O(1) per step — pairs with sliding window technique.
Sliding Window & Two Pointers
O(n) subarray / substring problems — a must-know technique missing from the theory
curriculum
#3
sliding windowMedium↗
#76
sliding windowHard↗
#15
two pointersMedium↗
Longest Substring Without Repeating Characters
Expand right, shrink left when you hit a duplicate — the sliding window template.
Minimum Window Substring
Variable-size sliding window with a frequency map — the hardest window problem.
3Sum
Sort, fix one element, two-pointer scan — O(n²) vs O(n³) brute force.
Trie (Prefix Tree)
O(L) string search/insert where L = key length — key data structure for autocomplete
and word searches
Backtracking
Exhaustive search with pruning — the algorithmic foundation behind NP-hard solvers
#46
backtrackingMedium↗
#78
backtracking / subsetsMedium↗
#37
backtracking + pruningHard↗
Permutations
Generate all permutations — the canonical backtracking template.
Subsets
Enumerate all 2ⁿ subsets — connects to the certificate verification idea from L17.
Sudoku Solver
Constraint-propagation + backtracking — an NP-complete problem solved in practice
with smart pruning.
Bit Manipulation
O(1) tricks with XOR, masks, and shifts — often the key to clean O(n) solutions
#136
XOR trickEasy↗
#191
bit countingEasy↗
#371
bit arithmeticMedium↗
Single Number
XOR every element — the unique one survives because x⊕x=0.
Number of 1 Bits
Count set bits — Kernighan's trick (n & (n-1) clears the lowest set bit) makes
this O(popcount).
Sum of Two Integers
Add without + or − using XOR and carry — forces you to think at the bit level.
Textbook references:
Greedy (L6–9) → KT §4. D&C (L10–12) → KT §5.
DP (L13–16) → KT §6 & CLRS §15 & §24.
NP (L17) → KT §8.
LP (L18–22) → LP Guide on the course site.
LeetCode explore cards for
Graphs and
Dynamic
Programming
are excellent companions.