LeetCode
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 86: Partition List
·2 mins
LeetCode
Medium
Linked-List
Two-Pointers
LeetCode 86 note: two dummies collect nodes below x and at least x, then join them, setting the second part’s tail to None
LeetCode 82: Remove Duplicates from Sorted List II
·2 mins
LeetCode
Medium
Linked-List
Two-Pointers
LeetCode 82 note: every duplicated value goes, the head included, so use a dummy; on a duplicate skip to the next different value and link prev.next past it
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
LeetCode 78: Subsets
·1 min
LeetCode
Medium
Array
Backtracking
Bit-Manipulation
LeetCode 78 note: each element is either taken or not; iteratively, each new number copies every existing subset with the number appended
LeetCode 77: Combinations
·2 mins
LeetCode
Medium
Backtracking
LeetCode 77 note: choose k of 1 to n with dfs(start, path), picking the next only after start to avoid duplicate combinations