Medium
LeetCode 1448: Count Good Nodes in Binary Tree
·1 min
LeetCode
Medium
Tree
Depth-First-Search
Breadth-First-Search
Binary-Tree
LeetCode 1448 note: pass the path maximum down during DFS; a node is good when its value is at least that maximum
LeetCode 143: Reorder List
·2 mins
LeetCode
Medium
Linked-List
Two-Pointers
Stack
Recursion
LeetCode 143 note: find the middle, reverse the second half, and merge the two alternately, cutting the first half’s tail
LeetCode 138: Copy List with Random Pointer
·2 mins
LeetCode
Medium
Hash-Table
Linked-List
LeetCode 138 note: the first pass maps old nodes to new ones, the second wires next and random; seed the dictionary with None -> None
LeetCode 105: Construct Binary Tree from Preorder and Inorder Traversal
·3 mins
LeetCode
Medium
Array
Hash-Table
Divide-and-Conquer
Tree
LeetCode 105 note: the first pre-order value is the root, and its position in the in-order tells the left subtree’s size; look positions up in a dictionary for O(n)
LeetCode 102: Binary Tree Level Order Traversal
·2 mins
LeetCode
Medium
Tree
Breadth-First-Search
Binary-Tree
LeetCode 102 note: BFS one whole level at a time, building the next level from the current one; an empty tree returns an empty list
LeetCode 981: Time Based Key-Value Store
·2 mins
LeetCode
Medium
Hash-Table
String
Binary-Search
Design
LeetCode 981 note: store a (timestamp, value) list per key, with timestamps increasing; get binary searches the last timestamp <= the query
LeetCode 875: Koko Eating Bananas
·2 mins
LeetCode
Medium
Array
Binary-Search
LeetCode 875 note: binary search the speed for the smallest k with total hours <= h, continuing left even when the hours equal h
LeetCode 424: Longest Repeating Character Replacement
·2 mins
LeetCode
Medium
Hash-Table
String
Sliding-Window
LeetCode 424 note: a variable sliding window where window length minus the top character count is the number of replacements; shrink when it exceeds k
LeetCode 153: Find Minimum in Rotated Sorted Array
·2 mins
LeetCode
Medium
Array
Binary-Search
LeetCode 153 note: compare mid with the right end: nums[mid] > nums[r] puts the minimum to the right, otherwise mid may be it, so r = mid
LeetCode 347: Top K Frequent Elements
·1 min
LeetCode
Medium
Array
Hash-Table
Divide-and-Conquer
Sorting
LeetCode 347 note: count first, then take the k most frequent with a size-k heap or a bucket sort indexed by count
LeetCode 238: Product of Array Except Self
·2 mins
LeetCode
Medium
Array
Prefix-Sum
LeetCode 238 note: each answer is the product of everything to the left times everything to the right; two passes, no division
LeetCode 167: Two Sum II - Input Array Is Sorted
·2 mins
LeetCode
Medium
Array
Two-Pointers
Binary-Search
LeetCode 167 note: sorted, so move two pointers inward, shifting right when the sum is too large and left when too small; indices are 1-based