Array
LeetCode 3796: Find Maximum Value in a Constrained Sequence
·2 mins
LeetCode
Medium
Greedy
Array
LeetCode 3796 note: each position’s bound is the min of its own limit, the left bound + difference and the right bound + difference; one pass each way
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 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 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 1512: Number of Good Pairs
·1 min
LeetCode
Easy
Math
Hash-Table
Counting
Array
LeetCode 1512 note: count while scanning; each number pairs with every earlier equal number, so add its current count to the answer
LeetCode 3731: Find Missing Elements
·1 min
LeetCode
Easy
Hash-Table
Sorting
Array
LeetCode 3731 note: the minimum and maximum are still present, so check every integer in between against a set
LeetCode 3712: Sum of Elements With Frequency Divisible by K
·1 min
LeetCode
Easy
Hash-Table
Counting
Array
LeetCode 3712 note: count each value, and for counts divisible by k add value × count