Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Vote For New Content
Why does maxRepeatLetterCount never reduce?

ahonliu

Jun 9, 2024

When the window shrinks, it is possible that maxRepeatLetterCount reduces, right?

7

0

Comments
Cristian Fărcaș
Cristian Fărcaș3 months ago

Indeed, the maxRepeatLetterCount should be reduced when window shrinks.

Alexei Tilikin
Alexei Tilikin25 days ago

I think you are right. Moreover, maxRepeatLetterCount must be recalculated every time we move windowStart. We just removed a letter from our window and if that was the most frequent letter, then another letter might become most frequent.

But we can't be sure. So we h...

Skylar Liang
Skylar Liang6 days ago

I think that's some sort of optimization to use the all-time max repeated instead of the current max repeated.

I find it more intuitive to ignore maxRepeatLetterCount and just get the max of frequency map values. The frequency map can at most have 26 entries & O(26) = ...