Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Longest Repeating Character Replacement

Medium

Topics
StringSliding WindowHash Table

Given a string s of uppercase English letters and an integer k, you may replace at most k characters with any uppercase letter. Return the length of the longest substring containing a single repeated letter you can obtain.

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 uppercase English letters.
  • 0 <= k <= s.length
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access