0
Challenge · 26Array & String Patterns
Sliding window: variable size
Patternsused in ~100% of apps
The single highest-return pattern in this tier. Nobody tells you how wide the window is. A rule does. The window grows greedily and shrinks only when it has to, and a whole family of questions that look unrelated turn out to be this one.
Core idea. Push the right edge out one step at a time, always. After each step, while the window breaks the rule, pull the left edge in. Every position enters once and leaves once, so the whole thing is one pass even though there are two loops.
poke it, drag it,
try to break it
try to break it
no slides here.
you drive.
you drive.
Playground, this isn't a screenshot
longest stretch with no repeated letter. "Abcabb"
a
b
c
a
b
b
a
b
c
a
b
b
a
b
c
a
b
b
a
b
c
a
b
b
a
b
c
a
b
b
a
b
c
a
b
b
a
b
c
a
b
b
Neither edge ever moves left. Six characters, ten edge-movements in total, not thirty-six.
↑ play a little first, then dig in