LeetCode
LeetCode 2106: Maximum Fruits Harvested After at Most K Steps
·2 mins
LeetCode
Hard
Sliding-Window
Prefix-Sum
Binary-Search
Array
LeetCode 2106 note: the harvest is always a contiguous block of fruits; covering [L, R] takes (R - L) + min(|start - L|, |R - start|) steps, so slide a window over the fruits array
LeetCode 3805: Count Caesar Cipher Pairs
·2 mins
LeetCode
Medium
Math
Hash-Table
String
Counting
LeetCode 3805 note: shift each string so its first letter is a, making Caesar-equivalent strings identical, then count pairs per normalized form
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 3803: Count Residue Prefixes
·1 min
LeetCode
Easy
Hash-Table
String
LeetCode 3803 note: add characters to a set while scanning; count a prefix when its distinct count equals its length % 3
LeetCode 2831: Find the Longest Equal Subarray
·2 mins
LeetCode
Medium
Sliding-Window
Hash-Table
Binary-Search
Array
LeetCode 2831 note: list the positions of each value and slide a window over that list; the deletions needed are the span of positions minus the number of copies
LeetCode 2779: Maximum Beauty of an Array After Applying Operation
·2 mins
LeetCode
Medium
Sliding-Window
Sorting
Binary-Search
Array
LeetCode 2779 note: each number can become anything in [x - k, x + k], so a group can become one value ⇔ max - min <= 2k; sort and find the longest such window
LeetCode 2730: Find the Longest Semi-Repetitive Substring
·2 mins
LeetCode
Medium
Sliding-Window
String
LeetCode 2730 note: the window holds at most one adjacent equal pair; when a new pair arrives, shrink the left until the previous pair leaves
LeetCode 2516: Take K of Each Character From Left and Right
·2 mins
LeetCode
Medium
Sliding-Window
Hash-Table
String
LeetCode 2516 note: taking from both ends leaves a middle block in which each letter may appear at most total − k times; find the longest such window
LeetCode 2271: Maximum White Tiles Covered by a Carpet
·2 mins
LeetCode
Medium
Sliding-Window
Greedy
Sorting
Prefix-Sum
Binary-Search
Array
LeetCode 2271 note: starting the carpet at some segment’s start is never worse; after sorting, two pointers sum the fully covered segments and count the last one partially
LeetCode 1838: Frequency of the Most Frequent Element
·2 mins
LeetCode
Medium
Sliding-Window
Sorting
Greedy
Prefix-Sum
Binary-Search
Array
LeetCode 1838 note: after sorting, raising the whole window to nums[right] costs nums[right] × length − window sum; shrink the left while that exceeds k
LeetCode 1458: Max Dot Product of Two Subsequences
·2 mins
LeetCode
Hard
Dynamic-Programming
Longest-Common-Subsequence
Array
LeetCode 1458 note: a two-prefix DP; dp[i][j] either pairs nums1[i] with nums2[j] (extending dp[i-1][j-1] or starting fresh) or skips one of them
LeetCode 3634: Minimum Removals to Balance Array
·2 mins
LeetCode
Medium
Sliding-Window
Sorting
Binary-Search
Array
LeetCode 3634 note: after sorting, what remains is always a contiguous block; for each minimum nums[left], a right-only pointer finds how far it can extend, and everything outside is removed