Trains the technique from
LeetCode 1589Maximum Sum Obtained of Any PermutationThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A belt has n slots. The parcel weights are given as nums, and you may load them onto the belt in any order, one weight per slot.
Each entry of requests is a pair [start, end] naming a stretch of slots, ends included. A scan of that stretch reports the total weight sitting in it.
Choose the loading order that makes the totals reported by all the scans add up to as much as possible, and return that sum modulo 10^9 + 7.
Example 1
The three stretches cover the slots 1, 2, 3, 2, 1 times from left to right. Loading 3, 9, 20, 12, 7 puts the heaviest parcel in the most-scanned slot, and the three scans then report 32, 48 and 32.
Example 2
The first two slots are scanned three times each and the last only once, so the lightest parcel goes at the end. The scans then report 37 three times and 8 once.
Example 3
Every parcel weighs nothing, so no order beats any other.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def max_sum_range_query(nums: list[int], requests: list[list[int]]) -> int:public int maxSumRangeQuery(int[] nums, int[][] requests)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.