Variable Size Sliding Window Algorithm

Find the Smallest Subarray with Sum Greater Than S

Problem Statement

Array: [2, 2, 1, 5, 3, 0]     Target Sum (S): 7

Goal: Find the smallest subarray whose sum is greater than 7

Variable Size Sliding Window Algorithm

Step 1: Expand window by moving right pointer until sum > target

Step 2: Contract window by moving left pointer while sum > target

Step 3: Track the minimum window size found

Left Pointer
Right Pointer
Current Window
Step 1 of 11
Window
[2]
Current Sum
2
Window Size
1
Min Valid Size
Not Found
Starting with window [2]. Sum = 2, which is ≤ 7. Need to expand window.