Sanket And Strings

Please explain if the question precisely. Also tell me what should be correct answer for string ‘ababaaaa’ for k=2.

hi @nikunj19093
the question describes the perfectness of a string as the maximum length substring with same characters
for eg aaa is perfect string of length 3
aaabb is not a perfect string because all characters are not same, but the substring “aaa” is perfect. the substring “bb” is also perfect. now the length of “aaa” is 3 and length of “bb” is 2, so we report the prefectness as 3 (because it is the maximum length perfect substring)

Now, you have to change some characters in the string such that maximum possible perfectness is achieved. You are allowed to change a maximum of k characters.

in the sample input, abba is given, and k = 2
now we can either change the string to aaaa (by changing s[1] and s[2]) or change the string to bbbb (by changing s[0] and s[3]). In both the cases the longest substring with equal characters is of length 4, hence the perfectness reported is 4. You have to change the characters in such a way that maximum perfectness can be achieved

for the string “ababaaaa” and k = 2, we can change s[1] to ‘a’ and s[3] to ‘a’ to make “aaaaaaaa”, the perfectness of this string will be 8

Please mark your doubt as resolved if you are satisfied