educative.io

Educative

See the explanation in the 'Solution' section above. What exact statement or line?

Could there be more details in comment section pointing at exact statement or part of the “Solution” above? Thanks in advance.


Course: Grokking the Coding Interview: Patterns for Coding Questions - Learn Interactively
Lesson: Longest Substring with Same Letters after Replacement (hard) - Grokking the Coding Interview: Patterns for Coding Questions

Hi @zugzug
Thanks for reaching out to us. The comment See the explanation in the Solution section above in the code is referring to the following paragraph in the lesson.
While shrinking the window, we don’t need to update maxRepeatLetterCount. Since we are only interested in the longest valid substring, our sliding windows do not have to shrink, even if a window may cover an invalid substring. Either we expand the window by appending a character to the right or we shift the entire window to the right by one. We only expand the window when the frequency of the newly added character exceeds the historical maximum frequency (from a previous window that included a valid substring). In other words, we do not need to know the exact maximum count of the current window. The only thing we need to know is whether the maximum count exceeds the historical maximum count, and that can only happen because of the newly added char.
I hope it helps. Happy Learning :slight_smile: