FastPrepRange Sum

Range Sum

Zolo logoZolo● HardINTERNOA

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 Zolo problems

See Zolo hiring insights
Saved
public int rangeSum(int[] arr, int lower, int upper) {
  // write your code here
}
arr[-2, 5, -1]
lower-2
upper2
expected3
Checking account…