Workspace Variable Window
0d
Problem-solving patterns

Variable-Width Window

Expand and shrink a span while maintaining a validity rule.

Recognition signal

Removing from the left can restore validity predictably.

Method

Update the right side, shrink to restore the invariant, then record a candidate at the correct time.

Worked example

While scanning “abba”, the second b forces removal through the first b.

Common mistake

For the shortest valid span, measure before a shrink makes it invalid.