Module 7 · Sliding Window · Sliding Window Advanced

Smallest distinct window

Grow the window until it holds every distinct character of the string, then shrink it from the left while it still does. The removal that breaks it shows the smallest good window ending at r - 1.