Leetcode 1615 Solution

This article provides solution to leetcode question 1615 (range-sum-of-sorted-subarray-sums)

https://leetcode.com/problems/range-sum-of-sorted-subarray-sums

Solution

class Solution:
    def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int:
        ans = 0

        sums = []
        for i in range(n):
            s = 0
            for j in range(i, n):
                s += nums[j]
                sums.append(s)

        sums.sort()

        return sum([sums[i] for i in range(left - 1, right)]) % (10**9 + 7)