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 = 2
Output:3
Explanation:

Ranges [0,0], [2,2], and [0,2] have sums -2, -1, and 2.

Input:nums = [1], lower = -2, upper = 2
Output:1
Explanation:

Edge case with a single-element array.

Input:nums = [0, -3, 2, 4, -1], lower = 1, upper = 3
Output:4
Explanation:

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

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!