| LC 67 |
Add Binary |
Easy |
Simultaneous Traversal + Carry |
- Clarify: Inputs contain only '0' and '1'?
- Pattern: Simultaneous Traversal + Carry
- Core: Identical structure to Add Two Numbers.
- Verify: Input: a="11", b="1" → Output: "100"
- Trap: Building result with string concatenation inside the loop: result = str(digit) + result.
|
O(max(m,n)) |
O(max(m,n)) |
Open |
| LC 100 |
Same Tree |
Easy |
DFS (Parallel Traversal) |
- Clarify: Are both trees possibly empty? (Yes)
- Pattern: DFS (Parallel Traversal)
- Core: Traverse both trees in lockstep.
- Verify: Input: p=[1,2,3], q=[1,2,3] -> true
- Trap: Checking only in-order traversals or value multisets.
|
O(n) |
O(h) |
Open |
| LC 110 |
Balanced Binary Tree |
Easy |
Post-Order DFS + Height Check |
- Clarify: Empty tree is balanced? (Yes)
- Pattern: Post-Order DFS + Height Check
- Core: Use post-order DFS so each node gets left/right heights from children first.
- Verify: Input: root=[3,9,20,null,null,15,7] -> true
- Trap: Computing height separately for each node (`isBalanced` calls `height` repeatedly) causes O(n^2) in skewed trees.
|
O(n) |
O(h) |
Open |
| LC 257 |
Binary Tree Paths |
Easy |
DFS + Path Building |
- Clarify: Return root-to-leaf only (not every path)?
- Pattern: DFS + Path Building
- Core: Classic DFS.
- Verify: Input: root=[1,2,3,null,5]
- Trap: Using one shared string without backtracking correctly.
|
O(n) |
O(h) |
Open |
| LC 270 |
Closest Binary Search Tree Value |
Easy |
BST Guided Traversal |
- Clarify: Return node value (not node reference)?
- Pattern: BST Guided Traversal
- Core: Use BST ordering to discard half the tree each step.
- Verify: Input: root=[4,2,5,1,3], target=3.714286 -> 4
- Trap: Doing full DFS/BFS over all nodes (O(n)) and ignoring BST property.
|
O(h) |
O(1) |
Open |
| LC 339 |
Nested List Weight Sum |
Easy |
DFS/BFS with Depth Tracking |
- Clarify: Root depth starts at 1?
- Pattern: DFS/BFS with Depth Tracking
- Core: Traverse all elements while carrying current depth.
- Verify: Input: nestedList=[[1,1],2,[1,1]]
- Trap: Forgetting to increment depth when descending into child lists causes underweighted sums.
|
O(n) |
O(d) |
Open |
| LC 543 |
Diameter of Binary Tree |
Easy |
DFS Height + Global Max |
- Clarify: Diameter measured in edges (not nodes)?
- Pattern: DFS Height + Global Max
- Core: At each node, candidate diameter is leftHeight + rightHeight.
- Verify: Input: [1,2,3,4,5]
- Trap: Returning `best` from recursion instead of node height.
|
O(n) |
O(h) |
Open |
| LC 938 |
Range Sum of BST |
Easy |
DFS + BST Pruning |
- Clarify: Range is inclusive [low, high]?
- Pattern: DFS + BST Pruning
- Core: DFS with pruning: if node value is smaller than low, skip entire left subtree; if larger than high, skip entire right subtree.
- Verify: Input: root=[10,5,15,3,7,null,18], low=7, high=15 -> 32
- Trap: Ignoring BST property and doing plain full-tree DFS every time.
|
O(n) worst-case, O(m) average with pruning |
O(h) |
Open |
| LC 2 |
Add Two Numbers |
Medium |
Simultaneous Traversal + Carry |
- Clarify: Digits stored in REVERSE order — head is the ones place? (This is the gift — no reversal needed)
- Pattern: Simultaneous Traversal + Carry
- Core: Simulate third-grade addition: add digit by digit from right to left, carrying overflow.
- Verify: Input: l1=2→4→3 (342), l2=5→6→4 (465)
- Trap: Loop condition 'while l1 OR l2' without the third condition 'OR carry != 0'.
|
O(max(m,n)) |
O(max(m,n)) |
Open |
| LC 98 |
Validate Binary Search Tree |
Medium |
DFS + Range Propagation |
- Clarify: Strictly less than or can equal values exist?
- Pattern: DFS + Range Propagation
- Core: Naive mistake: only check local parent-child relationship.
- Verify: Input: 2 Output: true
- Trap: Using only local parent-child check (node.left.val < node.val).
|
O(n) |
O(h) |
Open |
| LC 114 |
Flatten Binary Tree to Linked List |
Medium |
Morris Traversal |
- Clarify: In-place only — confirmed?
- Pattern: Morris Traversal
- Core: For each node: find the RIGHTMOST node of its left subtree (the pre-order predecessor).
- Verify: Input: 1 Output: 1→2→3→4→5→6
- Trap: Recursive solutions get pointer order wrong under pressure — you move a pointer before saving a reference and lose part of the tree.
|
O(n) |
O(1) |
Open |
| LC 129 |
Sum Root to Leaf Numbers |
Medium |
DFS Accumulating Path Value |
- Clarify: Node values are single digits 0..9?
- Pattern: DFS Accumulating Path Value
- Core: Carry a running number while traversing: `curr = curr*10 + node.val`.
- Verify: Input: root=[1,2,3]
- Trap: Collecting full path strings/arrays first and converting later adds unnecessary overhead.
|
O(n) |
O(h) |
Open |
| LC 133 |
Clone Graph |
Medium |
BFS + HashMap |
- Clarify: Can graph have cycles? (Yes — visited map prevents infinite loops)
- Pattern: BFS + HashMap
- Core: BFS/DFS traversal + HashMap {original → clone}.
- Verify: Input: adjList=[[2,4],[1,3],[2,4],[1,3]]
- Trap: Adding neighbors before checking visited — creates duplicate clone nodes for the same original.
|
O(V+E) |
O(V) |
Open |
| LC 173 |
Binary Search Tree Iterator |
Medium |
Controlled In-Order Traversal |
- Clarify: Average O(1) for next() — not worst-case?
- Pattern: Controlled In-Order Traversal
- Core: Simulate in-order traversal LAZILY — only compute the next element when next() is called.
- Verify: BSTIterator(root=[7,3,15,null,null,9,20])
- Trap: Claiming O(1) worst-case instead of AMORTIZED O(1).
|
Amortized O(1) |
O(h) |
Open |
| LC 199 |
Binary Tree Right Side View |
Medium |
BFS Level-Order |
- Clarify: Right side = last visible node at each depth level?
- Pattern: BFS Level-Order
- Core: BFS level-by-level.
- Verify: Input: 1 Output: [1,3,4]
- Trap: DFS left-first and taking last at each depth gets right/left priority backwards.
|
O(n) |
O(w) |
Open |
| LC 200 |
Number of Islands |
Medium |
BFS Flood Fill |
- Clarify: 4-directional connectivity only (no diagonals)?
- Pattern: BFS Flood Fill
- Core: Every time you find an unvisited '1', you've found a new island — increment counter.
- Verify: Input:
- Trap: Marking visited AFTER dequeuing instead of ON ENQUEUE.
|
O(m×n) |
O(min(m,n)) |
Open |
| LC 207 |
Course Schedule |
Medium |
Topological Sort (Kahn) |
- Clarify: Is prerequisite pair [a,b] meaning b -> a edge?
- Pattern: Topological Sort (Kahn)
- Core: A course plan is possible iff the prerequisite graph is acyclic.
- Verify: Input: numCourses=2, prerequisites=[[1,0]]
- Trap: Only running BFS/DFS from course 0 misses disconnected components.
|
O(V+E) |
O(V+E) |
Open |
| LC 210 |
Course Schedule II |
Medium |
Topological Sort (Kahn, Order Construction) |
- Clarify: Any valid topological order accepted?
- Pattern: Topological Sort (Kahn, Order Construction)
- Core: Same graph as LC 207, but instead of counting only, record dequeue order during Kahn's algorithm.
- Verify: Input: numCourses=2, prerequisites=[[1,0]]
- Trap: Using DFS without proper cycle-state tracking can return invalid partial orders.
|
O(V+E) |
O(V+E) |
Open |
| LC 211 |
Design Add and Search Words Data Structure |
Medium |
Trie + DFS Wildcard |
- Clarify: '.' matches any SINGLE letter — confirmed?
- Pattern: Trie + DFS Wildcard
- Core: Trie for prefix-matching structure.
- Verify: WordDictionary wd
- Trap: Using a flat list for storage and doing regex scan for search — gives O(n×m) per search where n=words stored.
|
O(m) add, O(26^m) search worst |
O(total chars) |
Open |
| LC 236 |
Lowest Common Ancestor of a Binary Tree |
Medium |
DFS Post-Order |
- Clarify: Are p and q guaranteed to exist? (Logic changes if not)
- Pattern: DFS Post-Order
- Core: Post-order DFS.
- Verify: Input: tree=[3,5,1,6,2,0,8,null,null,7,4], p=5, q=1
- Trap: Early-terminating when finding p without checking its subtree for q.
|
O(n) |
O(h) |
Open |
| LC 314 |
Binary Tree Vertical Order Traversal |
Medium |
BFS + Column Indexing |
- Clarify: Within same row/column, should order follow BFS left-to-right?
- Pattern: BFS + Column Indexing
- Core: Use BFS with (node, column).
- Verify: Input: [3,9,20,null,null,15,7]
- Trap: Using DFS without row tracking can break required ordering for nodes sharing the same column.
|
O(n) |
O(n) |
Open |
| LC 426 |
Convert Binary Search Tree to Sorted Doubly Linked List |
Medium |
In-Order Traversal + Pointer Stitching |
- Clarify: Output must be circular?
- Pattern: In-Order Traversal + Pointer Stitching
- Core: In-order traversal visits nodes in sorted order.
- Verify: Input: [4,2,5,1,3]
- Trap: Forgetting final head-tail linking.
|
O(n) |
O(h) |
Open |
| LC 545 |
Boundary of Binary Tree |
Medium |
Tree Traversal (Left Boundary + Leaves + Right Boundary) |
- Clarify: Boundary is anti-clockwise and starts with root?
- Pattern: Tree Traversal (Left Boundary + Leaves + Right Boundary)
- Core: Build answer in three non-overlapping passes: left boundary (top-down, skip leaves), leaves (full DFS), right boundary (top-down into temp, skip leaves, then reverse).
- Verify: Input: root=[1,null,2,3,4]
- Trap: Including leaves in left/right boundary loops duplicates them when leaf pass runs.
|
O(n) |
O(h) |
Open |
| LC 721 |
Accounts Merge |
Medium |
Union-Find + Email Graph |
- Clarify: Same name does not guarantee same person?
- Pattern: Union-Find + Email Graph
- Core: Union emails that appear in the same account.
- Verify: Input:
- Trap: Merging by name alone.
|
O(N alpha(N) + E log E) |
O(E) |
Open |
| LC 785 |
Is Graph Bipartite? |
Medium |
BFS 2-Coloring |
- Clarify: Can graph be disconnected? (Yes — MUST check ALL components)
- Pattern: BFS 2-Coloring
- Core: Try to 2-color the graph — color every node RED or BLUE such that no two adjacent nodes share a color.
- Verify: Input: graph=[[1,2,3],[0,2],[0,1,3],[0,2]]
- Trap: Not handling disconnected graphs.
|
O(V+E) |
O(V) |
Open |
| LC 863 |
All Nodes Distance K in Binary Tree |
Medium |
Tree to Undirected Graph + BFS |
- Clarify: Distance is number of edges?
- Pattern: Tree to Undirected Graph + BFS
- Core: Tree nodes only have child pointers, but distance-k search needs moving both downward and upward.
- Verify: Input: root=[3,5,1,6,2,0,8,null,null,7,4], target=5, k=2
- Trap: Forgetting a visited set causes infinite revisits between child and parent pointers after adding parent edges.
|
O(n) |
O(n) |
Open |
| LC 1091 |
Shortest Path in Binary Matrix |
Medium |
8-Direction BFS on Grid |
- Clarify: Moves allowed in all 8 directions (including diagonals)?
- Pattern: 8-Direction BFS on Grid
- Core: Treat each clear cell as an unweighted graph node and run BFS from (0,0).
- Verify: Input: grid=[[0,1],[1,0]] -> 2
- Trap: Using DFS/greedy can miss the shortest path in an unweighted graph.
|
O(n^2) |
O(n^2) |
Open |
| LC 1382 |
Balance a Binary Search Tree |
Medium |
In-Order Traversal + Rebuild from Sorted Array |
- Clarify: Need to preserve original node objects, or can create new nodes? (Either accepted on LeetCode)
- Pattern: In-Order Traversal + Rebuild from Sorted Array
- Core: In-order traversal of BST gives sorted values.
- Verify: Input: root=[1,null,2,null,3,null,4,null,null]
- Trap: Trying local AVL-style rotations from an arbitrary unbalanced BST is complex and error-prone for interviews.
|
O(n) |
O(n) |
Open |