**Problem Description**

Given an array **A** of **N** non-negative numbers and you are also given non-negative number **B**.

You need to find the **number of subarrays in A having sum less than B**. We may assume that there is no overflow.

1 <= N <= 10^{4}

1 <= A[i] <= 100

1 <= B <= 10^{8}

First argument is an integer array **A**.

Second argument is an integer **B**.

Return an integer denoting the **number of subarrays in A having sum less than B**.

Input 1:

A = [2, 5, 6] B = 10

Input 2:

A = [1, 11, 2, 3, 15] B = 10

Output 1:

4

Output 2:

4

Explanation 1:

The subarrays with sum less than B are {2}, {5}, {6} and {2, 5},

Explanation 2:

The subarrays with sum less than B are {1}, {2}, {3} and {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.

Sign Up

to access hints and editorial solutions for**Counting Subarrays!**

to access hints and editorial solutions for

Loading...