Search
⌘K

Leetcode 3691. Maximum Total Subarray Value II

Pick exactly k distinct non-empty subarrays (overlaps allowed) to maximize the sum of their ranges (max - min). The core challenge is to efficiently compute and rank subarray range values—by decomposing contributions of each element as a subarray maximum or minimum (monotonic stacks) and extracting the top-k totals—without enumerating all O(n^2) subarrays.


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Your account is free and you can post anonymously if you choose.