← problems
#424

Longest Repeating Character Replacement

MediumSliding Window

You are given a string s and an integer k. You may replace at most k characters so that the string contains the longest possible substring of a single repeating character. Return the length of that substring.

Example

s = "ABAB", k = 2    => 4   // replace both A's or both B's
s = "AABABBA", k = 1 => 4
Implement
function CharacterReplacement(s: string, k: int) -> int

Found a bug? Or annoyed about something in the language? Tell us.

loading editor…