A window compresses repeated work
For each right endpoint, remember the next position after the last occurrence of its character. The valid left boundary is the maximum of its current value and that remembered position, so it never moves backward. Each character enters once, giving linear time.