Every sliding window rests on one property: validity must be monotone — once a window
goes bad, growing it must keep it bad, so shrinking is the only sane move. “Every character appears
at least k times” is the opposite: an invalid window can be repaired by adding more
characters. a is invalid at k=2, and ababb is valid. So there is no shrink
rule, and Act 1 shows the window eating itself alive. Act 2 restores monotonicity by
fixing a parameter: pin the number of distinct characters to d, and
“too many distinct” is monotone, so a normal window works — run it once for each
d from 1 to 26 and take the best. The other standard fix is divide and conquer: any
character whose total count in a segment is below k can never appear in the answer, so split
the segment on it and recurse. Same answer, different lever — but only the fixed-d
version teaches you what to do the next time a window refuses to shrink.