You are given a list of positive numbers and a target.
Find the length of the shortest contiguous block (a run of side-by-side numbers) whose sum is greater than or equal to the target.
If no block reaches the target, the answer is infinity — there is no valid window.
The block [5, 2] adds up to 7 and has length 2. No single number reaches 7, so 2 is the shortest.
The single number 6 already meets the target, so the shortest window has length 1.
Even the whole list only sums to 3, so no window ever reaches 9.
1def smallest_window(nums, target):2 left = 03 current_sum = 04 min_len = infinity5 for right in range(len(nums)):6 current_sum += nums[right]7 while current_sum >= target:8 min_len = min(min_len, right - left + 1)9 current_sum -= nums[left]10 left += 111 return min_lenleft and right each only move forward, so every number is added once and removed at most once — one pass, not a nested scan.