Maximum Sum Obtained of Any Permutation SOLUTION

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
 

March Long Challenge 2021 Solutions

April Long Challenge 2021 Solutions

Codechef Long Challenge Solutions

February Long Challenge 2021

1. Frog Sort Solution Codechef

2. Chef and Meetings Solution Codechef

3. Maximise Function Solution Codechef

4. Highest Divisor Solution Codechef

5. Cut the Cake Challenge Solution Codechef

6. Dream and the Multiverse Solution Codechef

7. Cell Shell Solution Codechef

8. Multiple Games Solution Codechef

9. Another Tree with Number Theory Solution Codechef

10. XOR Sums Solution Codechef

11. Prime Game Solution CodeChef

12. Team Name Solution Codechef

January Long Challenge 2021

November Challenge 2020 SOLUTION CodeChef

October Lunchtime 2020 CodeChef SOLUTIONS

RELATED :

Related :

Related :

Leave a Comment

close
error: Content is protected !!