224. Longest Repeating Character Replacement

MediumStringString

Given a string s and integer k, you may change at most k characters to any uppercase letter. Return the length of the longest substring containing a single repeated letter achievable after the changes. Input: '"s", k'.

Input: '"s", k'.

Output: Integer — longest achievable repeating substring.

Examples

Example 1
Input: "ABAB", 2
Output: 4
Explanation: Change 2 to make 'AAAA' or 'BBBB'.
Example 2
Input: "AABABBA", 1
Output: 4
Explanation: Window 'AABA'->'AAAA'.
Example 3
Input: "AAAA", 0
Output: 4
Explanation: Already all same.

Constraints

Asked by

BloombergAmazonMicrosoftGoogleInfosysMeta
Solve this problem in the editor →