Skip to main content
mediumBlind 75

Longest Repeating Character Replacement

Given a string s and an integer k You can replace at most k characters to make a substring of repeating characters Return the length of the longest such substring Example: s = "ABAB", k = 2 => 4 (replace both A's with B's) Example: s = "AABABBA", k = 1 => 4 (replace one A to get "BBBB")

The window is valid while its length minus its most frequent count stays within k. I grow, then shrink only when that breaks.

Arrays & HashingStringTwo PointersSliding Window

Meet Coco

Coco is an AI study partner, not a person. She listens while you explain your code, asks what a line does and never hands you the fix. Typing with Coco is free when you sign in, up to a daily limit. Talking with her out loud comes with the $79 pack. Anyone can open the editor and run their code.

1Find Longest Substring with K Replacementsmedium
Based onLeetCode