Enumeration
Array Scanning
·7 mins
Algorithm
Array
Simulation
Enumeration
Adjacent comparisons and walking monotonic runs (uphill, downhill, hills and valleys), keeping prefix / suffix maximums and sums in one pass, enumerating pairs in small ranges, and breaking ties with tuple keys
LeetCode 2761: Prime Pairs With Target Sum
·2 mins
LeetCode
Medium
Math
Number-Theory
Sieve
Enumeration
Array
LeetCode 2761 note: sieve primes below n, then try x up to n / 2; when x and n - x are both prime, they form a pair
LeetCode 3548: Equal Sum Grid Partition II
·3 mins
LeetCode
Hard
Prefix-Sum
Hash-Table
Matrix
Enumeration
LeetCode 3548 note: try each horizontal cut (transpose for vertical); the difference must equal a cell on the larger side, and a one-row or one-column side can only drop an end cell, while any cell works otherwise
LeetCode 3984: Divisible Game
·3 mins
LeetCode
Medium
Dynamic-Programming
Kadane
Math
Number-Theory
Enumeration
LeetCode 3984 note: replacing a composite k by one of its prime factors only helps (more values divisible, smaller k), so try every prime factor of the numbers plus 2, running Kadane once per candidate
LeetCode 1878: Get Biggest Three Rhombus Sums in a Grid
·3 mins
LeetCode
Medium
Matrix
Enumeration
Heap
LeetCode 1878 note: enumerate every top vertex and size, walk the four edges, and keep the three largest distinct sums
LeetCode 3713: Longest Balanced Substring I
·2 mins
LeetCode
Medium
Hash-Table
String
Counting
Enumeration
LeetCode 3713 note: fix the start and extend right; “every character has the same count” means “highest count × kinds = length”, an O(1) check per step
LeetCode 3910: Count Connected Subgraphs with Even Node Sum
·3 mins
LeetCode
Hard
Bit-Manipulation
Enumeration
Graph
Union-Find
LeetCode 3910 note: n is tiny, so enumerate subsets with a bitmask, check the even sum first, then check that the induced subgraph is connected
LeetCode 3833: Count Dominant Indices
·2 mins
LeetCode
Easy
Array
Enumeration
LeetCode 3833 note: keep a suffix sum from the right and compare nums[i] × count > sum on the right, with no floats and without counting itself
LeetCode 3827: Count Monobit Integers
·1 min
LeetCode
Easy
Bit-Manipulation
Enumeration
LeetCode 3827 note: the only numbers with all-equal bits are 0 and 2^k - 1, so the count is (n + 1).bit_length()
LeetCode 2122: Recover the Original Array
·3 mins
LeetCode
Hard
Two-Pointers
Sorting
Hash-Table
Enumeration
Array
LeetCode 2122 note: the smallest number is always in lower, so enumerating its partner fixes k; after sorting, two pointers pair each smallest unmatched number with the number 2k above it
LeetCode 3804: Number of Centered Subarrays
·1 min
LeetCode
Medium
Hash-Table
Enumeration
Array
LeetCode 3804 note: fix the left end and extend right, adding to the sum and to a set; count the subarray when the sum is in the set
LeetCode 3799: Word Squares II
·2 mins
LeetCode
Medium
Backtracking
Enumeration
String
LeetCode 3799 note: four nested levels pruned by corner letters; sorting the words first makes the output lexicographic