Sliding Window
TimeO(n)SpaceO(k)
Grow a window to the right one character at a time. When a character repeats, shrink the window from the left, tracking the longest window seen.
Key idea. Grow a window right, shrink it left on a violation. Each element enters and leaves the window at most once — linear, not quadratic.
1
Loading…
—