Minimum Size Subarray Sum

Given an array A of n positive integers and a positive integer B,

find the minimal length of a contiguous subarray of which the sum ≥ B.

If there isn’t one, return 0 instead.

NOTE

Your code may be run on multiple testcases ( <= 50 ). Try to come up with an optimised solution.

CONSTRAINTS

1 <= n (size of array A) <= 10^5
1 <= A[i] <= 10^4
1 <= B <= 2*10^9

INPUT FORMAT

A : Array containing some integer elements
B : The number by which the sum of contiguous sub-array should be greater

SAMPLE INPUT

A : [ 2, 3, 1, 2, 4, 3 ]
B : 7

SAMPLE OUTPUT

2

EXPLANATION

The smallest possible sub array with sum >= 7 is [4,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 Minimum Size Subarray Sum on Interview Code Editor
Hints
  • Hints are not available for this problem

Discussion


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