Array
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 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 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 42: Trapping Rain Water
·2 mins
LeetCode
Hard
Array
Two-Pointers
Dynamic-Programming
Stack
LeetCode 42 note: each cell holds min(tallest on the left, tallest on the right) - its own height; use prefix and suffix maxima or two pointers
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
LeetCode 128: Longest Consecutive Sequence
·2 mins
LeetCode
Medium
Array
Hash-Table
Union-Find
LeetCode 128 note: put everything in a set and count upward only from values whose x - 1 is absent; each value is seen at most twice, O(n)
LeetCode 90: Subsets II
·2 mins
LeetCode
Medium
Array
Backtracking
Bit-Manipulation
LeetCode 90 note: sort first; for a number equal to the previous one, extend only the subsets created in the previous step
LeetCode 81: Search in Rotated Sorted Array II
·2 mins
LeetCode
Medium
Array
Binary-Search
LeetCode 81 note: with duplicates, nums[l] == nums[mid] hides which half is sorted, so just move l right by one; worst case O(n)
LeetCode 80: Remove Duplicates from Sorted Array II
·1 min
LeetCode
Medium
Array
Two-Pointers
LeetCode 80 note: keep each value at most twice by comparing with nums[k - 2], two slots back from the write position
LeetCode 79: Word Search
·3 mins
LeetCode
Medium
Array
String
Backtracking
Depth-First-Search
LeetCode 79 note: backtrack from every cell, matching the next character in four directions with visited cells marked temporarily and restored; prune early with character counts