FunctionRacerProblemsRace

Longest Repeating Character Replacement

MediumTwo pointersPython, JavaScript, TypeScript, Java, C++

You may change at most k characters of s to any other uppercase letter. After the changes, find the longest contiguous piece made of one repeated letter. Return the greatest length you can reach.

Example 1

s "ABAB"
k 2
returns 4

Change both A to B (or the other way) to get length 4.

Example 2

s "AABABBA"
k 1
returns 4

Changing one letter gives a run of 4.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Two pointers problems