Medium

Given a string s and an integer k. Choose any character of the string and change it to any other uppercase English character. You can do this at most k times.

Return the length of the longest substring containing the same letter you can get after performing the above operations.

 

Example

Input: s = "ABAB", k = 2 Output: 4

Explanation: Replace the two 'A's with two 'B's or two 'B' with two 'A'. The resultant string will be “AAAA” or “BBBB”. So the length longest substring with same letters will be 4 in any case.

 

Input: s = "AABABBA", k = 1 Output: 4

Explanation: Replace 'A' in the middle of string with 'B' to get "AABBBBA".

The substring "BBBB" has the longest repeating letters, which is 4.





Thanks for feedback.

Share Your Thoughts




Explore more in Fundesk DSA Curated Problems List
Common Element in all Rows of a Given Row-Wise Sorted Matrix
Product of array except self
Maximum product subarray
Remove duplicates from an unsorted singly linked list
Check for balanced brackets or valid parenthesis in an expression
Maximum sum from non-adjacent subsequence
Browse all Fundesk DSA Curated Problems List articles →