Given an integer array nums and two integers lower and upper, count the number of range sums whose values lie in the inclusive interval [lower, upper]. This is a well-known advanced Fenwick Tree problem after converting prefix sums into ordered ranks.
nums = integer array, lower and upper = inclusive sum bounds
number of subarrays with sum in [lower, upper]
Example 1:
Input:
nums = [-2,5,-1] lower = -2 upper = 2
Output:
3
Explanation:
The valid subarrays are [-2], [-2,5,-1], and [-1].
Example 2:
Input:
nums = [0] lower = 0 upper = 0
Output:
1
Explanation:
The single subarray [0] has sum 0, which lies in the target range.