Free written solutionRange Sum of Sorted Subarray Sums (LeetCode 1508): Solution and Explanation
Take every contiguous subarray sum of a positive array, sort them, and add up positions left through right. With nums = [1,2,3,4], left = 1 and right = 5 the sorted sums are [1,2,3,3,4,5,6,7,9,10] and the first five add up to 13.
Read the intuition, approach, code and complexity →