120. Count of Range Sum

HardArrayArray

Given an integer array nums and two integers lower and upper, return the number of range sums that lie in [lower, upper] inclusive. A range sum S(i,j) is the sum of nums[i..j] for i<=j. Input: '[nums], lower, upper'.

Input: '[nums], lower, upper'.

Output: Integer count.

Examples

Example 1
Input: [-2,5,-1], -2, 2
Output: 3
Explanation: Range sums in [-2,2]: [0,0]=-2,[2,2]=-1,[0,2]=2.
Example 2
Input: [0], 0, 0
Output: 1
Explanation: Single range sum 0.
Example 3
Input: [1,2,3], 3, 6
Output: 4
Explanation: Four range sums in [3,6].

Constraints

Asked by

InfosysGoogleAmazonMeta
Solve this problem in the editor →