#K47007. Minimum Size Subarray Sum
Minimum Size Subarray Sum
Minimum Size Subarray Sum
You are given an array of n positive integers and a target sum s. Your task is to find the minimal length of a contiguous subarray of which the sum is at least s. If no such subarray exists, output 0.
This problem can be efficiently solved using the sliding window technique with a time complexity of \(O(n)\).
Note: Input should be handled from standard input (stdin) and output should be printed to standard output (stdout).
inputFormat
The first line contains two integers n
and s
, where n
is the number of elements in the array and s
is the target sum.
The second line contains n
space-separated positive integers representing the array.
outputFormat
Output a single integer: the length of the shortest contiguous subarray whose sum is greater than or equal to s
. If there is no such subarray, output 0.
6 7
2 3 1 2 4 3
2
</p>