Problem Brief

Range Sum

INTERNOA

Return the number of range sums that lie in [lower, upper] inclusive.

1Example 1

Input
arr = [-2, 5, -1], lower = -2, upper = 2
Output
3
Explanation
There 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

2Example 2

Input
arr = [1, -3, 5, 2, 5, 2, -5], lower = -2, upper = 6
Output
8
Explanation
There are eight ranges with sums that fall within the range [-2, 6].

3Example 3

Input
arr = [1, -3, 5, -2, 2, 5, -1, 10], lower = 5, upper = 9
Output
12
Explanation
There are twelve ranges with sums that fall within the range [5, 9].

Constraints

Limits and guarantees your solution can rely on.

๐Ÿ‰๐Ÿ‰
public int rangeSum(int[] arr, int lower, int upper) {
  // write your code here
}
Input

arr

[-2, 5, -1]

lower

-2

upper

2

Output

3

Sign in to submit your solution.