#K15961. Minimum Subarray Length Sum
Minimum Subarray Length Sum
Minimum Subarray Length Sum
Given an array of integers and a target integer \(X\), find the minimum length of a contiguous subarray of which the sum is at least \(X\). If no such subarray exists, output 0.
This problem requires you to use efficient techniques such as the two-pointer (sliding window) method to achieve an optimal solution.
Example:
Input: arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], X = 15 Output: 2
In the above example, the subarray [7, 8] is the smallest contiguous subarray with a sum \(\ge 15\).
inputFormat
The first line contains an integer \(T\) denoting the number of test cases. Each test case consists of two lines:
- The first line contains two integers \(n\) and \(X\), where \(n\) is the size of the array and \(X\) is the target sum.
- The second line contains \(n\) space-separated integers representing the elements of the array.
Constraints: \(1 \leq n \leq 10^5\), \(1 \leq arr[i] \leq 10^4\), and \(1 \leq X \leq 10^9\). The overall sum of \(n\) over all test cases does not exceed \(10^6\).
outputFormat
For each test case, output a single integer which is the minimum length of a contiguous subarray whose sum is at least \(X\). If no such subarray exists, output 0.
## sample5
10 15
1 2 3 4 5 6 7 8 9 10
5 20
1 2 3 4 5
1 10
10
6 7
2 3 1 2 4 3
10 55
1 2 3 4 5 6 7 8 9 10
2
0
1
2
10
</p>