Longest Repeating Character Replacement
Practice this coding question on Coding Gurukul.
Problem statement
A sign workshop has a strip of uppercase letter tiles. It can repaint at most k tiles to any uppercase letter and wants the longest uninterrupted strip displaying just one repeated letter after those repairs. Your task Find the maximum length of a contiguous substring that can be made entirely one letter by replacing at most k characters. Important details You choose both the substring and the target letter. Replacements outside the chosen substring offer no benefit. Using fewer than k replacements is allowed, and k = 0 asks for an existing uniform run. Worked example For ABAB and k = 2, repaint the two B tiles as A. All four positions become equal, so the answer is 4.
Input format
First line: k. Second line: the uppercase string.
Output format
Print the maximum achievable length.
Constraints
1 <= length <= 100000; 0 <= k <= length; letters A-Z.
Sample input
2 ABAB
Sample output
4
Sign in to run or submit a solution in C++, Java or Python.