LeetCode 424 Longest Repeating Character Replacement - Problem Statement

The problem

Given a string s and an integer k, you can replace at most k characters with any other character. Return the length of the longest substring containing the same letter after performing at most k replacements.

With s = "AABABBA" and k = 1, the answer is 4. You can replace one B to get "AAAA" (a substring of the modified string).

Think about it: in any valid window, if you know the most frequent character, how many replacements do you need to make all characters match?

Constraints: 1n1051 \le n \le 10^5, 0kn0 \le k \le n.