1
// O(n) time | O(26) -> O(1) space - only uppercase English letters2
var characterReplacement = function (s, k) {5
if (k >= sLen) return sLen;9
for (let windowEnd = 0; windowEnd < sLen; windowEnd++) {10
// increment charCount11
charCount[s[windowEnd]]12
? charCount[s[windowEnd]]++13
: (charCount[s[windowEnd]] = 1);14
// calc max repeating char15
maxRepeatChar = Math.max(maxRepeatChar, charCount[s[windowEnd]]);16
// calc number of char that is not (or has fewer chars) repeating in window17
const remainingChar = windowEnd - windowStart + 1 - maxRepeatChar;18
// slide window by incrementing start of window19
if (remainingChar > k) {20
// decrement charCount21
charCount[s[windowStart]]--;25
maxLen = Math.max(maxLen, windowEnd - windowStart + 1);