It is mentioned to find the maximum substring with equal characters but then for input K=1 and “abbbbbbb” it is displaying 8 with the editorial code. That means the substring is “bbbbbbbb”. I don’t understand how this is equal characters when freq(a)=0 and freq(b) = 8.
This question is ambiguos
@jamesallenvinoy hey Allen this question is not ambiguous
Sanket has a string consisting of only a and b as the characters. Sanket describes perfectness of a string as the maximum length substring of equal characters. Sanket is given a number K which denotes the maximum number of characters he can change. Find the maximum perfectness he can generate by swapping no more than k characters.
Basically, there is a string which consists of only a and b. A substring is a contiguous sequence of characters within a string. Our aim is to generate substrings of a and b by swapping characters such that the lengths of substrings of either a or b is maximum possible. The only constraint we have here is that only k swaps are allowed. So, you have to tell the maximum possible length of the substrings that can be generated. By swapping, we mean that a can be replaced by b and b can be replaced by a.
For example:
Consider the following string: abba and k = 2
So, we can make only two swaps
abba (swaps = 0)
aaba (swaps = 1)
aaaa (swaps = 2)
Thus, the maximum length of substring is 4.
Consider the string: ababab and k=2
ababab (swaps = 0)
aaabab (swaps =1)
aaaaab (swaps = 2)
Thus, the maximum length of substring is 5.
and the case you’re talking about is
abbbbbbb k=1
abbbbbbb swap=0
bbbbbbbb swap=1
so the maximum length is 8
It is mentioned equal characters. My doubt is, if we are targetting either a or b then why is it mentioned equal characters?
Please don’t consider this as rude. My aim is to not make a single error while comprehending a question.
@jamesallenvinoy sanket is concerned about it future output. so you will given a string of a and b and you have to calculate the maximum length of substring as sanket describe after k swaps
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.