algorythms
Sliding Window
LC #424Medium

Longest Repeating Character Replacement

Sliding Window
GoogleAmazonBloomberg

Problem

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

Inputs = "AABABBA", k = 1
Output4
Why

Replace the one 'B' at index 5 → "AABAAABA". Longest run: "AAAA" = 4

Hints — reveal one at a time