#C13308. Minimum Size Subarray Sum
Minimum Size Subarray Sum
Minimum Size Subarray Sum
You are given an array nums
of n integers and a target integer target
. Your task is to find the minimal length of a contiguous subarray of which the sum is greater than or equal to target
. If there is no such subarray, output 0
.
This problem can be mathematically expressed as: $$\sum_{i=l}^{r}nums_i \geq target$$ where l
and r
are the indices of the subarray.
Note: The subarray must be contiguous.
inputFormat
The first line contains two integers n
and target
, where n
is the number of elements in the array and target
is the target sum.
The second line contains n
space-separated integers representing the array nums
.
outputFormat
Output a single integer representing the minimum length of a contiguous subarray whose sum is greater than or equal to target
. If no such subarray exists, output 0
.
6 7
2 3 1 2 4 3
2