Longest Repeating Character Replacement
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 uppercase English character.
Constraints:
s.length
s
consists of only uppercase English characters.k
s.length
Examples
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
What is the correct output for the following input values?
“abab”,
1
2
3
4
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.
Try it yourself
Implement your solution in the following coding playground.
import java.util.*;public class Solution{public static int longestRepeatingCharacterReplacement(String s, int k) {// Replace this placeholder return statement with your codereturn -1;}}