Description
Given an integer array nums and two integers lower and upper, return the number of range sums that lie in [lower, upper] inclusive.
Examples
Input:
nums = [-2,5,-1], lower = -2, upper = 2Output:
3Explanation:
Ranges [0,0], [2,2], and [0,2] have sums -2, -1, and 2.
Input:
nums = [1], lower = -2, upper = 2Output:
1Explanation:
Edge case with a single-element array.
Input:
nums = [0, -3, 2, 4, -1], lower = 1, upper = 3Output:
4Explanation:
The prefix sums are [0, 2, -1, 1, 2]. Range sums in [1,3]: [0,0]=2, [0,2]=1, [0,3]=2, [2,3]=3, [3,3]=2. Five range sums fall within [1,3].
Constraints
- •
1 ≤ nums.length ≤ 10⁵ - •
-2³¹ ≤ nums[i] ≤ 2³¹ - 1