Array
LeetCode 1464: Maximum Product of Two Elements in an Array
·1 min
LeetCode
Easy
Array
Sorting
Heap-Priority-Queue
LeetCode 1464 note: all values are positive, so take the two largest a and b and return (a - 1)(b - 1)
LeetCode 1337: The K Weakest Rows in a Matrix
·1 min
LeetCode
Easy
Array
Binary-Search
Sorting
Heap-Priority-Queue
LeetCode 1337 note: soldiers come first in each row, so binary search the first 0 for the count; sort by (count, row index) and take k
LeetCode 334: Increasing Triplet Subsequence
·2 mins
LeetCode
Medium
Array
Greedy
Longest-Increasing-Subsequence
LeetCode 334 note: keep the smallest first and the smallest second that has something smaller before it; any number above second completes a triplet
LeetCode 324: Wiggle Sort II
·2 mins
LeetCode
Medium
Array
Divide-and-Conquer
Greedy
Sorting
LeetCode 324 note: sort, split into a small half and a large half, reverse each, and interleave with small values at even indices and large ones at odd indices
LeetCode 473: Matchsticks to Square
·2 mins
LeetCode
Medium
Array
Dynamic-Programming
Backtracking
Bit-Manipulation
LeetCode 473 note: the total must be divisible by 4; place sticks from longest to shortest into one of four sides, skipping a side that would overflow or that equals a side already tried
LeetCode 435: Non-overlapping Intervals
·3 mins
LeetCode
Medium
Array
Dynamic-Programming
Greedy
Sorting
LeetCode 435 note: minimum removals = total minus the maximum kept; sort by right end and greedily keep the one ending earliest
LeetCode 396: Rotate Function
·2 mins
LeetCode
Medium
Array
Math
Dynamic-Programming
LeetCode 396 note: F(k) and F(k - 1) differ by one formula: F(k) = F(k - 1) + sum - n × the element moved to the front
LeetCode 313: Super Ugly Number
·2 mins
LeetCode
Medium
Array
Math
Dynamic-Programming
LeetCode 313 note: generalizing LC 264 with one pointer per prime; with a heap, avoid pushing the same number many times
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 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