...

/

Untitled Masterpiece

Try to solve the Longest Repeating Character Replacement problem.

Statement

Given a string s and an integer k, find the length of the longest substring in s, where all characters are identical, after replacing, at most, k characters with any other lowercase English character.

Constraints:

  • 11 \leq s.length 103\leq 10^3
  • s consists of only lowercase English characters
  • 00 \leq k \leq s.length

Example

Press + to interact
canvasAnimation-image
1 / 4

Understand the problem

Let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem:

Longest Repeating Character Replacement

1

What is the correct output for the following input values?

s=s = “abab”, k=2k = 2

A)

1

B)

2

C)

3

D)

4

Question 1 of 30 attempted

Figure it out!

We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding of how to solve this problem.

Sequence - Vertical
Drag and drop the cards to rearrange them in the correct sequence.

1
2
3
4
5

Try it yourself

Implement your solution in the following coding playground.

Press + to interact
JavaScript
usercode > main.js
function longestRepeatingCharacterReplacement(s, k) {
// Replace this placeholder return statement with your code
return -1;
}
export { longestRepeatingCharacterReplacement };
Longest Repeating Character Replacement

Access this course and 1200+ top-rated courses and projects.