Problem ยท Prefix Sum
Range Sum
Learn this problemProblem statement
Return the number of range sums that lie in [lower, upper] inclusive.
Function
rangeSum(arr: int[], lower: int, upper: int) โ intExamples
Example 1
arr = [-2, 5, -1]lower = -2upper = 2return = 3There are three ranges with sums that fall within the range [-2, 2]:
1. [-2] with sum -2
2. [-2, 5, -1] with sum 2
3. [-1] with sum -1
Example 2
arr = [1, -3, 5, 2, 5, 2, -5]lower = -2upper = 6return = 8There are eight ranges with sums that fall within the range [-2, 6].
Example 3
arr = [1, -3, 5, -2, 2, 5, -1, 10]lower = 5upper = 9return = 12There are twelve ranges with sums that fall within the range [5, 9].
Constraints
๐๐