dsa2 min read
Reverse Pairs [Hard] — Merge Sort with Cross-Half Counting
Count pairs (i,j) where i<j and nums[i]>2*nums[j] using modified merge sort to count cross-half pairs before merging.
Read →
webcoderspeed.com
1276 articles
Count pairs (i,j) where i<j and nums[i]>2*nums[j] using modified merge sort to count cross-half pairs before merging.
Minimize the largest sum among m subarrays by binary searching on the answer and greedy checking feasibility.
Find the shortest subarray with sum >= K using a monotonic deque on prefix sums, handling negative numbers correctly.
Count the number of range sums that lie in [lower, upper] using a merge sort approach on prefix sums.
Find three non-overlapping subarrays of length k with maximum sum using sliding window sums and left/right best index arrays.