Problem
You get a string s of uppercase English letters and an integer k. You can make at most k changes. In each change, you replace one character of s with a different uppercase letter.
A substring is a part of the string with consecutive characters. Return the length of the longest substring that contains only one letter after your changes.
Example 1
- Input:
- s = "BAAAB", k = 1
- Output:
- 4
- Explanation:
- Change the
"B"at index 4 to"A". Then the substring"AAAA"has the length 4.
Example 2
- Input:
- s = "XYZXY", k = 0
- Output:
- 1
- Explanation:
- You cannot make changes. No two characters next to each other are equal, so the answer is 1.
Example 3
- Input:
- s = "AABCCCCB", k = 2
- Output:
- 6
- Explanation:
- Change the two
"B"characters to"C". Then the substring from index 2 to index 7 contains only"C".
Constraints
- 1 <= s.length <= 10^5
- s contains only uppercase English letters.
- 0 <= k <= s.length
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- Longest Substring Without Repeating Characters
Coding · Hash Table · Sliding Window · String
- Longest Substring with At Most K Distinct Characters
Coding · Hash Table · Sliding Window · String
- Find All Anagrams in a String
Coding · Hash Table · Sliding Window · String
- Maximum Number of Occurrences of a Substring
Coding · Hash Table · Sliding Window · String
Sources · 2 references
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 1 record
Meta
Leetcode 424. Longest Repeating Character Replacement
Reported Oct 8, 2025 · 1 source report
MID_LEVEL
Source snapshot: Nov 12, 2026
View source
LeetCode company tags · 5 records
D. E. Shaw
Longest Repeating Character Replacement
Reported date not specified · Source window: 6mo
Source snapshot: Oct 20, 2026
Source frequency score: 91.4. This is not an interview probability.
View sourceGoldman Sachs
Longest Repeating Character Replacement
Reported date not specified · Source window: 6mo
Source snapshot: Oct 20, 2026
Source frequency score: 48. This is not an interview probability.
View sourceMicrosoft