Loading…
Loading…
Given an array of positive integers and a target sum, find the minimal length of a contiguous subarray whose sum is greater than or equal to the target. Print 0 if no such subarray exists.
Input: target = 7, nums = 2 3 1 2 4 3
Output: 2 (the subarray 4 3)
A variable-size window: expand right while the sum is below target; once it meets or exceeds target, shrink from the left while recording the minimum window length, then keep expanding.
Line 1: target Line 2: the array, space-separated
Input (stdin)
Output
Input (stdin)
Output
Sign in to track solved problems and earn XP.