Array and string patterns
Sliding window
Reuse work across adjacent ranges.
Understand the problem
Grow the right boundary and shrink the left until the window is valid. Track exactly the state needed to validate the window. Variable windows require a monotonic condition.
Make it concrete
For the longest unique substring, maintain character counts and shrink while the newest character appears twice.
Trade-offs and pitfalls
A sum-based window does not generally work with arbitrary negative numbers.
Check your understanding
Trace the longest unique substring in abcaac.
Practice this topic