Hard
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 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 1793: Maximum Score of a Good Subarray
·3 mins
LeetCode
Hard
Two-Pointers
Greedy
Binary-Search
Array
Monotonic-Stack
LeetCode 1793 note: expand from k toward the larger neighbor each step so the minimum stays as large as possible for each length; at a boundary, only the other side can grow
LeetCode 2972: Count the Number of Incremovable Subarrays II
·2 mins
LeetCode
Hard
Two-Pointers
Binary-Search
Array
LeetCode 2972 note: what remains is a strictly increasing prefix plus suffix; for each valid prefix end, a right-only pointer finds the first suffix start that can follow it, and every later start works too
LeetCode 2122: Recover the Original Array
·3 mins
LeetCode
Hard
Two-Pointers
Sorting
Hash-Table
Enumeration
Array
LeetCode 2122 note: the smallest number is always in lower, so enumerating its partner fixes k; after sorting, two pointers pair each smallest unmatched number with the number 2k above it
LeetCode 1782: Count Pairs Of Nodes
·3 mins
LeetCode
Hard
Two-Pointers
Graph
Sorting
Hash-Table
Counting
LeetCode 1782 note: count pairs with deg[a] + deg[b] > q using sorted degrees and converging pointers, then correct the over-count for pairs that share edges
LeetCode 992: Subarrays with K Different Integers
·2 mins
LeetCode
Hard
Sliding-Window
Hash-Table
Counting
Array
LeetCode 992 note: “exactly k kinds” = “at most k” − “at most k - 1”, where each at-most window adds right - left + 1 per right end
LeetCode 3298: Count Substrings That Can Be Rearranged to Contain a String II
·2 mins
LeetCode
Hard
Sliding-Window
Hash-Table
String
LeetCode 3298 note: rearrangeable to start with word2 ⇔ every character count is at least word2’s; an “at least” counting window where meet tracks how many characters have reached their target
LeetCode 632: Smallest Range Covering Elements from K Lists
·3 mins
LeetCode
Hard
Heap
K-Way-Merge
Sliding-Window
LeetCode 632 note: a heap of each list’s current element plus the running maximum; always advance the smallest
LeetCode 3816: Lexicographically Smallest String After Deleting Duplicate Characters
·3 mins
LeetCode
Hard
Stack
Monotonic-Stack
Greedy
String
LeetCode 3816 note: a monotonic stack that deletes a larger top while another copy exists, then trims duplicate letters off the end since a prefix is always smaller
LeetCode 2968: Apply Operations to Maximize Frequency Score
·2 mins
LeetCode
Hard
Sliding-Window
Sorting
Prefix-Sum
Binary-Search
Array
LeetCode 2968 note: after sorting, the cheapest common target for a block is its median; prefix sums give the cost in O(1), and it grows with the window, so slide
LeetCode 2302: Count Subarrays With Score Less Than K
·2 mins
LeetCode
Hard
Sliding-Window
Prefix-Sum
Binary-Search
Array
LeetCode 2302 note: score = sum × length with positive numbers grows with the window; shrink while the score is >= k, and right - left + 1 valid subarrays end at right