Problem ยท Prefix Sum
โ— HardZolostaysINTERNOA

Problem statement

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

Function

rangeSum(arr: int[], lower: int, upper: int) โ†’ int

Examples

Example 1

arr = [-2, 5, -1]lower = -2upper = 2return = 3
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

Example 2

arr = [1, -3, 5, 2, 5, 2, -5]lower = -2upper = 6return = 8
There 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 = 12
There are twelve ranges with sums that fall within the range [5, 9].

Constraints

๐Ÿ‰๐Ÿ‰

More Zolostays problems

drafts saved locally
public int rangeSum(int[] arr, int lower, int upper) {
  // write your code here
}
arr[-2, 5, -1]
lower-2
upper2
expected3
checking account