Medium
LeetCode 1750: Minimum Length of String After Deleting Similar Ends
·3 mins
LeetCode
Medium
Two-Pointers
String
LeetCode 1750 note: when both ends match, each side eats its whole run of that character; a string of one repeated character can be deleted entirely
LeetCode 1616: Split Two Strings to Make Palindrome
·3 mins
LeetCode
Medium
Two-Pointers
String
Greedy
LeetCode 1616 note: greedily match a’s prefix against b’s suffix from the outside in; the leftover middle must be a palindrome entirely within a or b, and both directions need checking
LeetCode 1498: Number of Subsequences That Satisfy the Given Sum Condition
·2 mins
LeetCode
Medium
Two-Pointers
Sorting
Binary-Search
Array
LeetCode 1498 note: only the minimum and maximum matter, so order does not and we can sort; fixing nums[left] as the minimum, the elements between are free, giving 2^(right - left) choices
LeetCode 1156: Swap For Longest Repeated Character Substring
·2 mins
LeetCode
Medium
Sliding-Window
Hash-Table
String
LeetCode 1156 note: for each character c, find the longest window with at most one non-c; the swapped-in c must come from elsewhere, so the length is capped at the total count of c
LeetCode 2401: Longest Nice Subarray
·2 mins
LeetCode
Medium
Sliding-Window
Bit-Manipulation
Array
LeetCode 2401 note: pairwise AND 0 ⇔ each bit is used by at most one number; a mask holds the window’s bits, and on a conflict the left shrinks and its bits are removed
LeetCode 1712: Ways to Split Array Into Three Subarrays
·4 mins
LeetCode
Medium
Binary-Search
Prefix-Sum
Two-Pointers
LeetCode 1712 note: fix the first cut and find the valid range of the second cut with two bisects or two monotonic pointers
LeetCode 825: Friends Of Appropriate Ages
·3 mins
LeetCode
Medium
Two-Pointers
Sorting
Binary-Search
Array
LeetCode 825 note: after sorting, the people someone can invite have ages in (0.5 × age + 7, age], a contiguous range kept with two same-direction pointers, minus the person themself
LeetCode 3306: Count of Substrings Containing Every Vowel and K Consonants II
·2 mins
LeetCode
Medium
Sliding-Window
Hash-Table
String
LeetCode 3306 note: “exactly k consonants” is not monotonic; compute “all five vowels and at least k consonants” minus “at least k + 1”, both “at least” counting windows
LeetCode 930: Binary Subarrays With Sum
·2 mins
LeetCode
Medium
Sliding-Window
Prefix-Sum
Hash-Table
Array
LeetCode 930 note: “sum exactly goal” = “sum at most goal” − “sum at most goal - 1”; or prefix sums with a hash map
LeetCode 2537: Count the Number of Good Subarrays
·2 mins
LeetCode
Medium
Sliding-Window
Hash-Table
Array
LeetCode 2537 note: adding x creates cnt[x] new equal pairs and removing it loses cnt[x] - 1; an “at least k pairs” counting window with count += left
LeetCode 3325: Count Substrings With K-Frequency Characters I
·2 mins
LeetCode
Medium
Sliding-Window
Hash-Table
String
LeetCode 3325 note: an “at least one character appears k times” counting window; when the new character reaches k, keep shrinking until it drops to k - 1
LeetCode 2962: Count Subarrays Where Max Element Appears at Least K Times
·2 mins
LeetCode
Medium
Sliding-Window
Array
LeetCode 2962 note: an “at least k” counting window: keep shrinking while the max appears k times, after which every left end in [0, left) is valid, so count += left