Smallest subarray with a sum greater than X

Question

Given an array of integers and a number X, can you find the smallest subarray with sum greater than the given value? If there isn't a possible subarray, print "Not possible".

For example:

arr[] = [1, 4, 45, 6, 0, 19]
x  =  51
Output: 3
# the array is [4, 45, 6]

arr[] = [1, 10, 5, 2, 7]
x  = 9
Output: 1
# the array is [10]

Solution

Access restricted

Subscribe to premium account to see the solution.

Get premium now