dsa · medium

Longest Repeating Character Replacement

You may replace at most k characters of s. Return the length of the longest substring that can be made of **one** repeating character after those replacements.

Arguments

Example

s = "ABAB", k = 24 (replace both As or both Bs).

s = "AABABBA", k = 14 (for example AABA by replacing the B).

Constraints

1 <= s.length <= 10^5 0 <= k <= s.length s consists of uppercase English letters Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.

Examples

Example 1

Input:
"ABAB"
2

Expected:
4

Example 2

Input:
"AABABBA"
1

Expected:
4

Open in the Dojo editor