Educative

If statement question

Inside the if statement that checks whether we have too many letters compared to k, do we really need to decrement the count of the letter at the start of the window?

This:

if (window_end - window_start + 1 - max_repeat_letter_count) > k:
  left_char = str1[window_start]
  frequency_map[left_char] -= 1
  window_start += 1

could just be this:

if (window_end - window_start + 1 - max_repeat_letter_count) > k:
  window_start += 1

Am I missing something? TIA

Yes you are missing, we do need to decrement the count of the letter at the start of the window as if in input we have some string where a character substring appears consecutively at more than one place then the answer would be wrong if you use your code.
Try using the following string as input and compare your answer.
aabbcbcdeeceeaabaaaaa and k =1

If we won’t decrement the count of the letter at the start of the window then our answer would be 10 which is wrong. The correct answer is 8 which is achieved using the decrement.