Count of Range Sum

Given an array of integers A and two integers B and C.
Find the number of range sums that lie in [ B, C ] inclusive.

Range sum S(i, j) is defined as the sum of the elements in A between indices i and j (i ≤ j), inclusive.



Input Format

The argument given is the integer array A and two integers B and C.

Output Format

 Find the number of range sums that lie in  [ B, C ] inclusive.

Constraints

1 <= length of the array <= 50000
-10^9 <= A[i] <= 10^9 

For Example

Input 1:
    A = [1, 2, 3]
    B = 4
    C = 6
Output 1:
    2
    Range Sum that lie between 4 and 6 are 6(1+2+3) and 5(2+3)

Input 2:
    A = [-5, 1, -2]
    B = -2
    C = 4
Output 2:
    3
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Count of Range Sum on Interview Code Editor
Sign Up
to access hints and editorial solutions for Count of Range Sum

Discussion


Loading...
Click here to start solving coding interview questions