Sliding Window
LC #424Medium
Longest Repeating Character Replacement
Sliding Window
GoogleAmazonBloombergProblem
Given a string and integer k, find the length of the longest substring where you can replace at most k characters to make all characters the same.
stringsliding-window
Constraints
- ›1 ≤ s.length ≤ 10⁵
- ›0 ≤ k ≤ s.length
- ›s consists of uppercase English letters only
Example
Input
s = "AABABBA", k = 1Output
4Why
Replace the one 'B' at index 5 → "AABAAABA". Longest run: "AAAA" = 4