Longest substring made uniform with at most k replacements
A weather station logs one character per day: S for sun, R for rain, C for cloud, and so on. Some days were logged wrongly, and a forecaster may correct up to k of them. They want to know the longest stretch of consecutive days that could all show the same weather after those corrections.
Implement longestUniformRun(text, k). It returns the length of the longest substring of text that can be turned into a single repeated character by replacing at most k of its characters.
longestUniformRun(text, k) // => number
text does not matter.'a' and 'A' are different. Every character (letters, digits, spaces, punctuation) is a valid label.k is a non-negative integer, and it can be larger than text.length. The answer can never exceed text.length.k = 0 the answer is the length of the longest run of one repeated character.0.text can be tens of thousands of characters long, so the solution must run in linear time.longestUniformRun('SSRSSCSS', 1); // => 5 ('SSRSS' or 'SSCSS' with one fix)
longestUniformRun('SSRSSCSS', 2); // => 8 (fix both R and C)
longestUniformRun('SSRSSCSS', 0); // => 2
longestUniformRun('XYYXYYYX', 1); // => 6 ('YYXYYY')
longestUniformRun('abc', 5); // => 3
longestUniformRun('aAaA', 1); // => 3 ('aAa' becomes 'aaa')
longestUniformRun('', 3); // => 0