A window is valid if windowSize - maxFreq <= k. You keep the most frequent character and replace the rest.
Track frequency of each character in window.
Track the maximum frequency seen.
If windowSize - maxFreq > k, window is invalid. Shrink from left.
Update result with valid window size.
Key optimization: you don't need to decrease maxFreq when shrinking. A smaller window with a smaller max frequency won't beat the current best.