Expand the right edge, and whenever a duplicate appears, shrink the left edge until the window is valid again.