Question bank › Sliding Window
Dsa Sliding Window Hard

Longest Repeating Character Replacement

Given a string s and an integer k, you can replace at most k characters in the string to make all characters in the string the same. Return the length of the longest substring that can be obtained. Input: - The first line contains an integer n (1 ≤ n ≤ 10^5): the length of the string. - The second line contains the string s (1 ≤ |s| ≤ 10^5): a string of lowercase letters. - The third line contains an integer k (1 ≤ k ≤ n): the maximum number of characters you can replace. Output: - A single integer representing the length of the longest substring that you can obtain. Example: Input: 5 AABAB 1 Output: 4

Key concepts

sliding_windowstrings

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.