You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// 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 changing no more than k characters.
7
+
8
+
// Input Format
9
+
// The first line contains an integer denoting the value of K. The next line contains a string having only ‘a’ and ‘b’ as the characters.
10
+
11
+
// Constraints
12
+
// 2 ≤ N ≤ 10^6
13
+
14
+
// Output Format
15
+
// A single integer denoting the maximum perfectness achievable.
16
+
17
+
// Sample Input
18
+
// 2
19
+
// abba
20
+
// Sample Output
21
+
// 4
22
+
// Explanation
23
+
// We can swap the a's to b using the 2 swaps and obtain the string "bbbb". This would have all the b's and hence the answer 4.
24
+
// Alternatively, we can also swap the b's to make "aaaa". The final answer remains the same for both cases.
0 commit comments