educative.io

Educative

Longest Substring with Same Letters after Replacement

When we are shrinking the window, why are we decrementing the left_char’s frequency in the frequency map? What is role of this step?
Even though I commented the decrementing left char’s part still we got the expected output.
This step resembles the replacement of ANY character?
I am aware that the maximum times we could decrement ANY left_char’s frequency is k times.

Kindly request you to bridge the disconnect.


Type your question above this line.

Course: https://www.educative.io/collection/5668639101419520/5671464854355968
Lesson: https://www.educative.io/collection/page/5668639101419520/5671464854355968/6497958910492672

Hi @learn

Although there can be a lengthy theoretical answer to your question, I would like you to test the code once by including “decrementing left char’s part” and then by excluding it with the following input:

String: accaabbccbbbaccaabbccbbbb
K: 2

You will see the difference in the output of both. Now you may understand the need for decrementing leftChar.