Longest Substring with Same Letters after Replacement (hard)
Problem Statement
Given a string with lowercase letters only, if you are allowed to replace no more than k
letters with any letter, find the length of the longest substring having the same letters after replacement.
Example 1:
Input: String="aabccbb", k=2
Output: 5
Explanation: Replace the two 'c' with 'b' to have the longest repeating substring "bbbbb".
Example 2:
Input: String="abbcb", k=1
Output: 4
Explanation: Replace the 'c' with 'b' to have the longest repeating substring "bbbb".
Example 3:
Input: String="abccde", k=1
Output: 3
Explanation: Replace the 'b' or 'd' with 'c' to have the longest repeating substring "ccc".
Try it yourself
Try solving this question here:
class CharacterReplacement {public static int findLength(String str, int k) {// TODO: Write your code herereturn -1;}}
Solution
This problem follows the ...