InferenceAI

Enter at least two characters to search.

Start free

Repeating Letter Replacement

mediumSliding Window25 min25 XP

You may change at most k characters of the uppercase string s to any other uppercase letter. Return the length of the longest substring containing a single repeated letter you can get.

Examples

EXAMPLE WALKTHROUGHreplace two

A guided view of the published example, not a trace of your code.

INPUT["ABAB",2]
TASKrepeating_letter_replacement()
EXPECTED OUTPUT4

Start with the input values shown in this example.

Example 1 of 3

Input: s = "ABAB", k = 2

Output: 4

Explanation: replace two

Input: s = "AABABBA", k = 1

Output: 4

Explanation: replace one

Input: s = "AAAA", k = 0

Output: 4

Explanation: already uniform

Hint 1

A window is valid when its length minus the count of its most common letter is at most k.

Topics

DSASliding WindowPython