Dashboard
LC #424

Longest Repeating Character Replacement

Pattern · ?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.

Constraints

  • 1 ≤ s.length ≤ 10⁵
  • 0 ≤ k ≤ s.length
  • s consists of uppercase English letters only

Example

Input
s = "AABABBA", k = 1
Output
4
Why
Replace the one 'B' at index 5 → "AABAAABA". Longest run: "AAAA" = 4

Spot the pattern

Which pattern cracks it?

Hints

One at a time
Solve on LeetCode ↗