Medium
LeetCode 3795: Minimum Subarray Length With Distinct Sum At Least K
·2 mins
LeetCode
Medium
Sliding-Window
Hash-Table
Array
LeetCode 3795 note: a shortest-window slide where each value counts once; track each value’s last position, and subtract the left value only if it was the last occurrence
LeetCode 2653: Sliding Subarray Beauty
·2 mins
LeetCode
Medium
Sliding-Window
Hash-Table
Array
LeetCode 2653 note: values are only -50 to 50, so the fixed window keeps a count array, and each window accumulates upward from -50 to find the x-th smallest negative
LeetCode 1888: Minimum Number of Flips to Make the Binary String Alternating
·2 mins
LeetCode
Medium
Sliding-Window
String
Dynamic-Programming
LeetCode 1888 note: rotations become length-n windows over s + s; the window’s mismatches against 0101… are diff, and against 1010… they are n - diff
LeetCode 3788: Maximum Score of a Split
·1 min
LeetCode
Medium
Prefix-Sum
Array
LeetCode 3788 note: build the suffix minimum first, then accumulate the prefix sum from the left and try every split
LeetCode 3694: Distinct Points Reachable After Substring Removal
·2 mins
LeetCode
Medium
Sliding-Window
Prefix-Sum
Hash-Table
String
LeetCode 3694 note: the endpoint is the total displacement minus the removed segment’s displacement; a length-k window tracks that segment and each endpoint goes into a set
LeetCode 2134: Minimum Swaps to Group All 1's Together II
·2 mins
LeetCode
Medium
Sliding-Window
Array
LeetCode 2134 note: the 1s end up in a circular window as long as their count, and the swaps needed equal the 0s in that window; slide around the circle for the minimum
LeetCode 3679: Minimum Discards to Balance Inventory
·3 mins
LeetCode
Medium
Sliding-Window
Hash-Table
Simulation
Counting
Array
LeetCode 3679 note: the rule already decides what must be discarded, so simulate it; the length-w window counts only kept arrivals, and discarded ones must not be subtracted when they leave
LeetCode 2461: Maximum Sum of Distinct Subarrays With Length K
·2 mins
LeetCode
Medium
Sliding-Window
Hash-Table
Array
LeetCode 2461 note: in a fixed window of length k, all values are distinct exactly when the number of distinct values equals k
LeetCode 1423: Maximum Points You Can Obtain from Cards
·1 min
LeetCode
Medium
Sliding-Window
Prefix-Sum
Array
LeetCode 1423 note: taking k cards from the ends leaves a contiguous middle of n - k cards; find its minimum sum with a fixed-size window
LeetCode 2841: Maximum Sum of Almost Unique Subarray
·2 mins
LeetCode
Medium
Sliding-Window
Hash-Table
Array
LeetCode 2841 note: a fixed window of length k keeps a sum and a count map; the number of distinct values is the map’s size, so delete keys that drop to zero
LeetCode 3709: Design Exam Scores Tracker
·2 mins
LeetCode
Medium
Binary-Search
Prefix-Sum
Design
LeetCode 3709 note: times are increasing, so store prefix sums and answer queries with two bisects; always parenthesize mid
LeetCode 3708: Longest Fibonacci Subarray
·1 min
LeetCode
Medium
Array
LeetCode 3708 note: lengths 1 and 2 always work; from the third element, extend while nums[i] == nums[i-1] + nums[i-2], otherwise reset to 2