↓Skip to main content

Array

LeetCode 3835: Count Subarrays With Cost Less Than or Equal to K
·2 mins
LeetCode Medium Sliding-Window Monotonic-Queue Queue Array
LeetCode 3835 note: cost = (max - min) × length only grows as the window grows, so a sliding window counts subarrays; two monotonic deques keep the window’s max and min
LeetCode 3834: Merge Adjacent Equal Elements
·2 mins
LeetCode Medium Stack Simulation Array
LeetCode 3834 note: a stack simulation where a new element merges with an equal top, possibly again with the new top
LeetCode 3833: Count Dominant Indices
·2 mins
LeetCode Easy Array Enumeration
LeetCode 3833 note: keep a suffix sum from the right and compare nums[i] × count > sum on the right, with no floats and without counting itself
LeetCode 3379: Transformed Array
·1 min
LeetCode Easy Array Simulation
LeetCode 3379 note: moving nums[i] steps right or left is nums[(i + nums[i]) % n]; Python’s % returns a non-negative result for negatives too
LeetCode 244: Shortest Word Distance II
·2 mins
LeetCode Medium Two-Pointers Design Hash-Table String Array
LeetCode 244 note: precompute each word’s positions (sorted by construction), then answer each query by merging the two position lists with two pointers, always advancing the smaller one
LeetCode 986: Interval List Intersections
·2 mins
LeetCode Medium Two-Pointers Sweep-Line Array
LeetCode 986 note: two pointers each hold an interval, the intersection is [max(starts), min(ends)], and the interval that ends first cannot meet anything else, so its pointer advances
LeetCode 3828: Final Element After Subarray Deletions
·2 mins
LeetCode Medium Math Brainteaser Game-Theory Array
LeetCode 3828 note: Alice can leave only the first or last element on her first move, guaranteeing max(first, last); Bob can likewise keep only an end, and one deletion changes at most one end, so the answer is max(first, last)
LeetCode 1537: Get the Maximum Score
·3 mins
LeetCode Hard Dynamic-Programming Two-Pointers Greedy Array
LeetCode 1537 note: two sorted arrays can switch only at shared values; merge with two pointers, keep a running sum per path, and at a shared value set both to the larger sum plus that value
LeetCode 809: Expressive Words
·3 mins
LeetCode Medium Two-Pointers String Array
LeetCode 809 note: two pointers compare runs of equal characters; when the lengths differ, the run in s must be at least 3 and no shorter than the word’s run, and both strings must end together
LeetCode 442: Find All Duplicates in an Array
·1 min
LeetCode Medium Hash-Table Array
LeetCode 442 note: values are in 1..n, so mark v with the sign of nums[v-1]; on the second visit it is already negative
LeetCode 41: First Missing Positive
·3 mins
LeetCode Hard Hash-Table Array
LeetCode 41 note: the answer is in 1..n+1; replace impossible values with n+1 (not 0) and mark v as seen with the sign of nums[v-1]
LeetCode 2570: Merge Two 2D Arrays by Summing Values
·2 mins
LeetCode Easy Two-Pointers Array
LeetCode 2570 note: merge two id-sorted arrays with two pointers, adding values when ids match