Minimum Size Subarray Sum

Minimum Size Subarray Sum (Smallest subarray whose sum is greater than or equal to target).

Given an array of positive integers and a positive number k. Find the smallest contiguous subarray whose sum is either greater than or equal to k. If no subarray is found then return 0.

For example –

Example 1 –

  Input :  {7, 2, 1, 1, 6, 5},  k = 11

Output:  2 ( subarray {6, 5} has the minimum length )

Example 2 –

  Input : {1, 4, 3},   k = 12

Output: 0 (No subarray is possible)