educative.io

Longest Substring with Same Letters after Replacement if condition clarity

Hi Sir,

I did not understand the logic of this statement

if (windowEnd - windowStart + 1 - maxRepeatLetterCount > k) {

can you please explain.

Current window size = windowEnd - windowStart+1.
So if current window is having length 5 and maxRepeatLetterCount is 3 then current window will be having 2 distinct character. Those can be replaced.