educative.io

Can we replace different characters with the same character or replacing characters must be the same as well

The letters being replaced must be the same alphabet (i-e acccgfac, k=3 are we only allowed to replace ccc?)
or the characters being replaced can be different alphabets as well (i-e acccgfac, k=3 we are allowed to replace gfa?)


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 @bee1
Yes, the replaced letters can be from the same or different alphabets.

thx @Usman_Tariq
The solution talks about max Repeating characters. Max Repeating Characters consecutive? or they can appear separately?
for example aaabb. a is maxRepeating character with frequency=3
aabcbdb In this case a is max repeating (frequency = 2) character or b (frequency = 3 but non consecitive)?

Also, is replacement allowed for consecutive letters only?
ABAB, k=2
Can we replace the 2 As with B or vice versa even though both As are not neighbours?


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 @bee1,
Max repeating characters should be consecutive.
For example: In the string of aabcbdbsa, the max repeating character is a with the frequency of 2 because only two a’s appear consecutively.
We hope Educative has inspired you to further your learning, and please drop us a note if you have any other questions or concerns. Thank you!

Hi @bee1,
Characters could be replaced even if they do not occur consecutively.
For example: If string = aabcdbbbcbxb, and k = 4, the max_repeating_character is b with the frequency of 10.

thx usman.