Medium
LeetCode 240: Search a 2D Matrix II
·2 mins
LeetCode
Medium
Array
Binary-Search
Divide-and-Conquer
Matrix
LeetCode 240 note: start at the top-right corner, moving left when larger and down when smaller, eliminating a row or column each step
LeetCode 229: Majority Element II
·2 mins
LeetCode
Medium
Array
Hash-Table
Sorting
Counting
LeetCode 229 note: at most two values can exceed n / 3; Boyer-Moore keeps two candidates and a second pass verifies their counts
LeetCode 216: Combination Sum III
·1 min
LeetCode
Medium
Array
Backtracking
LeetCode 216 note: use only 1 to 9, each at most once, choosing exactly k numbers that sum to n
LeetCode 151: Reverse Words in a String
·1 min
LeetCode
Medium
Two-Pointers
String
LeetCode 151 note: split() with no argument treats runs of spaces as one separator and drops leading and trailing spaces; reverse and join with single spaces
LeetCode 204: Count Primes
·2 mins
LeetCode
Medium
Array
Math
Enumeration
Number-Theory
LeetCode 204 note: the sieve of Eratosthenes, crossing out multiples of each prime p starting at p², with the outer loop only up to √n
LeetCode 189: Rotate Array
·2 mins
LeetCode
Medium
Array
Math
Two-Pointers
LeetCode 189 note: take k %= n, then reverse three times: the whole array, the first k, and the last n - k, with O(1) extra space
LeetCode 162: Find Peak Element
·2 mins
LeetCode
Medium
Array
Binary-Search
LeetCode 162 note: nums[mid] < nums[mid + 1] guarantees a peak to the right (rising until the edge at worst), otherwise one at or left of mid
LeetCode 134: Gas Station
·2 mins
LeetCode
Medium
Array
Greedy
LeetCode 134 note: if total gas is short there is no answer; otherwise scan, and whenever the tank goes negative move the start to the next station
LeetCode 137: Single Number II
·2 mins
LeetCode
Medium
Array
Bit-Manipulation
LeetCode 137 note: with everything else appearing three times, count the 1s at each bit modulo 3; the leftover bits form the answer, minding negatives
LeetCode 106: Construct Binary Tree from Inorder and Postorder Traversal
·2 mins
LeetCode
Medium
Array
Hash-Table
Divide-and-Conquer
Tree
LeetCode 106 note: the last post-order value is the root; taking roots from the end of the post-order, build the right subtree before the left
LeetCode 93: Restore IP Addresses
·2 mins
LeetCode
Medium
String
Backtracking
LeetCode 93 note: cut into exactly 4 pieces, each 1 to 3 digits long, valued 0 to 255, with no leading zero except 0 itself
LeetCode 647: Palindromic Substrings
·2 mins
LeetCode
Medium
Two-Pointers
String
Dynamic-Programming
LeetCode 647 note: expand around centers, counting one palindromic substring for each successful expansion