Hash-Table
LeetCode 1001: Grid Illumination
·3 mins
LeetCode
Hard
Hash-Table
Array
LeetCode 1001 note: one counter each for rows, columns and both diagonals (r - c, r + c), plus a set of lit lamps; turning one off decrements all four
LeetCode 4067: Longest Subarray With Restricted Pair Sums
·2 mins
LeetCode
Medium
Sliding-Window
Hash-Table
Array
LeetCode 4067 note: subarrays of a valid window stay valid, so slide; adding x only needs checks involving x: x as an addend (x + y in the window) or x as the sum (x - y in the window)
LeetCode 2561: Rearranging Fruits
·2 mins
LeetCode
Hard
Greedy
Hash-Table
Sorting
LeetCode 2561 note: every value’s total must be even; sort the excess, and each cheap half item swaps with an expensive one at min(its value, 2 × global minimum)
LeetCode 4019: Merge Close Characters II
·2 mins
LeetCode
Medium
Hash-Table
String
LeetCode 4019 note: kept characters never change again, so record each character’s last position in the result; a new character within k of it gets merged away
LeetCode 996: Number of Squareful Arrays
·3 mins
LeetCode
Hard
Dynamic-Programming
Bitmask
Backtracking
Math
Hash-Table
LeetCode 996 note: with n at most 12, use bitmask DP: dp[mask][last] = permutations using the set mask and ending with last; dedupe by using equal values in index order
LeetCode 2963: Count the Number of Good Partitions
·2 mins
LeetCode
Hard
Math
Combinatorics
Hash-Table
Array
LeetCode 2963 note: all occurrences of a value must share a part, so last occurrences cut the array into b indivisible blocks; each boundary may be cut or not, giving 2^(b-1)
LeetCode 3873: Maximum Points Activated with One Addition
·2 mins
LeetCode
Hard
Union-Find
Hash-Table
Array
LeetCode 3873 note: merge points sharing an x or y into components; a new point joins at most two of them, so the answer is the two largest plus 1
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 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 3960: Frequency Balance Subarray
·2 mins
LeetCode
Medium
Hash-Table
Counting
Array
LeetCode 3960 note: n is only 1000, so fix the left end and extend right while maintaining value -> count and count -> how many; exactly two counts f and 2f means balanced
LeetCode 3900: Longest Balanced Substring After One Swap
·3 mins
LeetCode
Medium
Prefix-Sum
Hash-Table
String
LeetCode 3900 note: equal prefix differences mean balanced; a substring off by 2 also works if a swappable character exists outside, and keeping the two earliest positions per difference is enough
LeetCode 522: Longest Uncommon Subsequence II
·2 mins
LeetCode
Medium
Two-Pointers
String
Sorting
Array
Hash-Table
LeetCode 522 note: the longest uncommon subsequence is always a whole string; check strings from longest to shortest, and the first that is not a subsequence of any other long-enough string is the answer