Longest Repeating Character Replacement
MediumP2Coding
You are given a string s of uppercase English letters and an integer k. In one operation you may change any character of s to any other uppercase letter, and you may do at most k operations.
Return the length of the longest substring that can be made of one repeated letter using at most k operations.
Example 1
- Input
- s = "ABAB", k = 2
- Output
- 4
Example 2
- Input
- s = "AABABBA", k = 1
- Output
- 4
Example 3
- Input
- s = "A", k = 0
- Output
- 1
Constraints
- 1 <= s.length <= 10^5
- s consists of uppercase English letters.
- 0 <= k <= s.length
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 12. ⌘Enter runs, ⌘⇧Enter submits.