Applied AI Engineer (LLM) coding learning path Level 2 This level · 12 of 31

Longest Repeating Character Replacement

Medium Sliding window String

Problem

Given a string of uppercase English letters and an integer k, you may replace at most k characters. Return the length of the longest substring that can be made of one repeated letter after those replacements.

Original: LeetCode 424: Longest Repeating Character Replacement.

Examples

Example 1

Input`s = "ABAB", k = 2`
Output`4`

Example 2

Input`s = "AABABBA", k = 1`
Output`4`

Constraints

  • 1 <= s.length <= 10^5
  • s consists of only uppercase English letters.
  • 0 <= k <= s.length

Hints

Solution

Tried it yourself? The approach, complexity, and code stay hidden until you choose.

Sources (1)
  1. LeetCode 424: Longest Repeating Character Replacementleetcode.com
Previous
Next