Medium
LeetCode 109: Convert Sorted List to Binary Search Tree
·2 mins
LeetCode
Medium
Linked-List
Divide-and-Conquer
Tree
Binary-Search-Tree
LeetCode 109 note: take the middle found with fast and slow pointers as the root and recurse on both halves; the height balances naturally
LeetCode 236: Lowest Common Ancestor of a Binary Tree
·2 mins
LeetCode
Medium
Tree
Depth-First-Search
Binary-Tree
Binary-Lifting
LeetCode 236 note: recursion returns whichever of p or q a subtree contains; finding something on both sides means they split here, so this node is the LCA
LeetCode 222: Count Complete Tree Nodes
·2 mins
LeetCode
Medium
Binary-Search
Bit-Manipulation
Tree
Binary-Tree
LeetCode 222 note: in a complete tree, equal leftmost depths on both sides mean one side is perfect, counted as 2^h - 1, for O(log² n)
LeetCode 129: Sum Root to Leaf Numbers
·2 mins
LeetCode
Medium
Tree
Depth-First-Search
Binary-Tree
LeetCode 129 note: on the way down multiply the current number by 10 and add the node’s value, adding it to the total at a leaf
LeetCode 117: Populating Next Right Pointers in Each Node II
·2 mins
LeetCode
Medium
Linked-List
Tree
Depth-First-Search
Breadth-First-Search
Binary-Tree
LeetCode 117 note: connect next pointers level by level with BFS; for a non-perfect tree, looking only at the neighbour’s children breaks the chain
LeetCode 116: Populating Next Right Pointers in Each Node
·2 mins
LeetCode
Medium
Linked-List
Tree
Depth-First-Search
Breadth-First-Search
LeetCode 116 note: in a perfect binary tree, walk each level through the next pointers already set on the level above: left.next = right and right.next = next.left, with O(1) extra space
LeetCode 113: Path Sum II
·2 mins
LeetCode
Medium
Backtracking
Tree
Depth-First-Search
Binary-Tree
LeetCode 113 note: backtrack with the current path and store a copy at a leaf whose total matches; values can be negative, so no early pruning
LeetCode 107: Binary Tree Level Order Traversal II
·1 min
LeetCode
Medium
Tree
Breadth-First-Search
Binary-Tree
LeetCode 107 note: a normal level-order traversal reversed at the end gives bottom-up order
LeetCode 103: Binary Tree Zigzag Level Order Traversal
·1 min
LeetCode
Medium
Tree
Breadth-First-Search
Binary-Tree
LeetCode 103 note: a normal level-order traversal with every odd level reversed gives the zigzag
LeetCode 402: Remove K Digits
·2 mins
LeetCode
Medium
String
Stack
Greedy
Monotonic-Stack
LeetCode 402 note: a monotonically increasing stack; while deletions remain, pop any top larger than the current digit, then strip leading zeros
LeetCode 334: Increasing Triplet Subsequence
·2 mins
LeetCode
Medium
Array
Greedy
Longest-Increasing-Subsequence
LeetCode 334 note: keep the smallest first and the smallest second that has something smaller before it; any number above second completes a triplet
LeetCode 324: Wiggle Sort II
·2 mins
LeetCode
Medium
Array
Divide-and-Conquer
Greedy
Sorting
LeetCode 324 note: sort, split into a small half and a large half, reverse each, and interleave with small values at even indices and large ones at odd indices