Shortest Window Reaching the Target
L4 Easy Sliding Window
When every element is non-negative, a window whose sum is at least the target can shrink from the left and still stay valid — the classic "shrink-when-satisfied" sliding window.
Given an array nums of positive integers and a positive target, return the length of the shortest contiguous subarray whose sum is at least target. If no such subarray exists, return 0.
Examples
▸ target = 7, nums = [2, 3, 1, 2, 4, 3]
→ 2
▸ target = 4, nums = [1, 4, 4]
→ 1
▸ target = 11, nums = [1, 1, 1, 1, 1, 1, 1, 1]
→ 0