424. Longest Repeating Character Replacement (ref to 1004
T: O(n)
S: O(1)
classSolution {publicintcharacterReplacement(String s,int k) {int[] charCount =newint[26]; // all uppercase , use int array to save countint left =0;int right =0;int maxCount =0;int result =0;while (right <s.length()) { charCount[s.charAt(right) -'A']++; maxCount =Math.max(maxCount, charCount[s.charAt(right) -'A']); // get maximum count right++;while (right - left - maxCount > k) { charCount[s.charAt(left) -'A']--; left++; } result =Math.max(result, right - left); }return result; }}/*count max charAABABBAl r -> cal max l r -> cal l r -> shrink left right - left - max > 1 -> not fit, shrink left right - left - max <= k -> fit result, cal*/