#K88207. Minimum Size Subarray Sum

    ID: 37257 Type: Default 1000ms 256MiB

Minimum Size Subarray Sum

Minimum Size Subarray Sum

You are given an array of n positive integers and a target integer x. Your task is to find the length of the smallest contiguous subarray whose sum is greater than or equal to x. If no such subarray exists, return 0.

The problem can be formally stated as follows:

Given an array \(a_1, a_2, \ldots, a_n\) and an integer \(x\), find the minimal length \(L\) such that there exists an index \(i\) with \(\sum_{j=i}^{i+L-1} a_j \ge x\). If no such \(L\) exists, print 0.

This is a classic sliding window problem that can be solved efficiently using the two-pointer technique.

inputFormat

The first line contains two space-separated integers: n (the number of elements in the array) and x (the target sum). The second line contains n space-separated positive integers representing the elements of the array.

outputFormat

Output a single integer representing the length of the smallest contiguous subarray whose sum is greater than or equal to x. If no such subarray exists, output 0.

## sample
6 7
2 3 1 2 4 3
2

</p>