Problem
Ask
Submissions

Problem: Range Sum of Sorted Subarray Sums

Medium
30 min
Understand how to calculate and sum the elements of sorted continuous subarray sums within a given range. This lesson guides you through sorting and search strategies to solve the problem efficiently, including handling large results using modulo operations. Practice implementing your solution in a coding environment.

Statement

You are given an integer array nums containing nn positive integers along with left and right. Calculate the sum of its elements for every non-empty continuous subarray of nums. Collect these sums into a new array and sort it in nondecreasing order. This will result in a new array of size n×(n+1)/2n \times (n + 1) /2.

Your task is to return the sum of the elements in this sorted array from the index left to right (inclusive with 1-based indexing).

Note: As the result can be large, return the sum modulo 109+710^9 + 7.

Constraints:

  • n=n = nums.length

  • 11 \leq nums.length 1000\leq 1000

  • 11 \leq nums[i] 100\leq 100

  • 11 \leq left \leq right n×(n+1)/2\leq n \times (n + 1) / 2

Problem
Ask
Submissions

Problem: Range Sum of Sorted Subarray Sums

Medium
30 min
Understand how to calculate and sum the elements of sorted continuous subarray sums within a given range. This lesson guides you through sorting and search strategies to solve the problem efficiently, including handling large results using modulo operations. Practice implementing your solution in a coding environment.

Statement

You are given an integer array nums containing nn positive integers along with left and right. Calculate the sum of its elements for every non-empty continuous subarray of nums. Collect these sums into a new array and sort it in nondecreasing order. This will result in a new array of size n×(n+1)/2n \times (n + 1) /2.

Your task is to return the sum of the elements in this sorted array from the index left to right (inclusive with 1-based indexing).

Note: As the result can be large, return the sum modulo 109+710^9 + 7.

Constraints:

  • n=n = nums.length

  • 11 \leq nums.length 1000\leq 1000

  • 11 \leq nums[i] 100\leq 100

  • 11 \leq left \leq right n×(n+1)/2\leq n \times (n + 1) / 2