Whew, that was a section full of moving edges! In each exercise, you kept a summary of one contiguous region and updated it as the edges moved, instead of recomputing it from scratch. Each value enters the window once and leaves at most once, so the total work stays linear even when an inner loop moves the left edge several steps.
Here’s what the window tracked in each exercise:
- Largest Fixed Total: A running sum gained the incoming value and lost the outgoing one. Starting from the first window, and not from zero, handles all-negative input.
- Vowel Window: The same fixed window tracked a count, so both the entering and the leaving character mattered.
- Longest Unique Segment: A repeated character pushed the left edge forward, sometimes past several characters, until the window was valid again.
- Limited Character Variety: Per-character counts had to drop keys that reached zero, or the number of distinct characters stayed wrong.
- Shortest Positive Total: You kept shrinking a valid window to find a shorter one. That only works because every value is positive.
- Rearranged Pattern Match: A window the length of the pattern compared letter counts, and the fixed alphabet kept the extra space constant.
Here’s a quick puzzle for Shortest Positive Total. Take the numbers 5, -3, 4, and 4 with a target of 8. The shrinking window reports a length of 4, but the last two values reach 8 on their own. Can you spot where it went wrong? Constraints like positivity are a big part of what makes a window safe to shrink.
Maybe a window of yours kept one character too many, or a count never dropped back to zero. Those slips happen to everyone, and they’re useful, because they show you which part of the window’s bookkeeping is still fuzzy. Pick the exercise that took you the most attempts, and in two or three sentences, explain what first went wrong and what changed your mind.