# Maximum Sum Obtained of Any Permutation SOLUTION

Page Contents

### Maximum Sum Obtained of Any Permutation SOLUTION Biweekly Contest 35

We have a variety of whole numbers, nums, and a variety of solicitations where requests[i] = [starti, endi]. The ith demand requests the whole of nums[starti] + nums[starti + 1] + … + nums[endi – 1] + nums[endi]. Both starti and endi are 0-listed.

Return the greatest all out whole of all solicitations among all stages of nums.

Since the appropriate response might be excessively enormous, return it modulo 109 + 7.

Model 1:

Information: nums = [1,2,3,4,5], demands = [[1,3],[0,1]]

Yield: 19

Clarification: One stage of nums is [2,1,3,4,5] with the accompanying outcome:

requests[0] – > nums[1] + nums[2] + nums[3] = 1 + 3 + 4 = 8

requests[1] – > nums[0] + nums[1] = 2 + 1 = 3

Absolute entirety: 8 + 3 = 11.

A stage with a higher all out total is [3,5,4,2,1] with the accompanying outcome:

requests[0] – > nums[1] + nums[2] + nums[3] = 5 + 4 + 2 = 11

requests[1] – > nums[0] + nums[1] = 3 + 5 = 8

All out whole: 11 + 8 = 19, which is as well as can be expected do.

Model 2:

Info: nums = [1,2,3,4,5,6], demands = [[0,1]]

Yield: 11

Clarification: A change with the maximum complete aggregate is [6,5,4,3,2,1] with demand totals [11].

Model 3:

Info: nums = [1,2,3,4,5,10], demands = [[0,2],[1,3],[1,1]]

Yield: 47

Clarification: A change with the maximum complete aggregate is [4,10,5,3,2,1] with demand totals [19,18,10].

Limitations:

n == nums.length

1 <= n <= 105

0 <= nums[i] <= 105

1 <= requests.length <= 105

requests[i].length == 2

0 <= starti <= endi < n