Array
LeetCode 448: Find All Numbers Disappeared in an Array
·1 min
LeetCode
Easy
Array
Hash-Table
LeetCode 448 note: use the array itself as the hash table, marking nums[x - 1] negative for each x; positions still positive are the missing numbers
LeetCode 414: Third Maximum Number
·1 min
LeetCode
Easy
Array
Sorting
LeetCode 414 note: track the three largest distinct values, skipping repeats, and return the maximum if fewer than three distinct values exist
LeetCode 350: Intersection of Two Arrays II
·1 min
LeetCode
Easy
Array
Hash-Table
Two-Pointers
Binary-Search
LeetCode 350 note: an intersection keeping multiplicity, where Counter’s & takes the smaller count from each side
LeetCode 349: Intersection of Two Arrays
·1 min
LeetCode
Easy
Array
Hash-Table
Two-Pointers
Binary-Search
LeetCode 349 note: convert both arrays to sets and intersect them
LeetCode 283: Move Zeroes
·1 min
LeetCode
Easy
Array
Two-Pointers
LeetCode 283 note: the write pointer advances only on non-zero values, swapping with them, which pushes zeros to the back
LeetCode 268: Missing Number
·1 min
LeetCode
Easy
Array
Hash-Table
Math
Binary-Search
LeetCode 268 note: the sum of 0..n minus the array’s sum is the missing number, which may be 0
LeetCode 228: Summary Ranges
·2 mins
LeetCode
Easy
Array
LeetCode 228 note: scan once, extending the current range when a number continues the previous one and opening a new range otherwise, then format
LeetCode 219: Contains Duplicate II
·2 mins
LeetCode
Easy
Array
Hash-Table
Sliding-Window
LeetCode 219 note: a hash map stores each value’s last index; only the most recent occurrence needs a distance check
LeetCode 217: Contains Duplicate
·1 min
LeetCode
Easy
Array
Hash-Table
Sorting
LeetCode 217 note: if converting to a set shortens the array, there is a duplicate
LeetCode 169: Majority Element
·2 mins
LeetCode
Easy
Array
Hash-Table
Divide-and-Conquer
Sorting
LeetCode 169 note: Boyer-Moore voting, where different values cancel in pairs and the survivor is the one appearing more than half the time
LeetCode 136: Single Number
·1 min
LeetCode
Easy
Array
Bit-Manipulation
LeetCode 136 note: x ^ x = 0 and x ^ 0 = x, so XOR everything; pairs cancel and the single number remains
LeetCode 119: Pascal's Triangle II
·2 mins
LeetCode
Easy
Array
Dynamic-Programming
LeetCode 119 note: only row rowIndex is needed; update a 1D array from right to left for O(k) space