Longest Repeating Character Replacement

Sliding Window, problem 4 of 7

Longest Repeating Character Replacement

Medium

LC #424

stringhash mapvariable window

Not attempted yet

s contains only uppercase English letters. You may change at most k characters, each to any uppercase letter.

Return the length of the longest substring made of a single repeated letter that you can end up with.

Example 1

Input: s = "ABAB", k = 2
Output: 4
Change both A's to B (or both B's to A).

Example 2

Input: s = "AABABBA", k = 1
Output: 4
Change the middle "A" of "BABB" to get "BBBB".

Example 3

Input: s = "ABCDE", k = 1
Output: 2

Constraints

  • 1 ≤ len(s) ≤ 10^5
  • 0 ≤ k ≤ len(s)

Python

Loading draft…

Test results

9 tests available

No results yet

Run tests your code against the examples; Submit runs the hidden tests too.

3 examples, 6 hidden

Run examples, then submit all tests.