#148 · Sliding window · Advanced · 135 XP · about 25 min
s is a string of uppercase letters. You may change up to k of its characters, each into any uppercase letter you like. Write longest_after_changes(s, k) that returns the length of the longest block of one repeated letter you can make.
longest_after_changes('ABBCB', 1) # returns 4 longest_after_changes('XYZ', 0) # returns 1 longest_after_changes('AAAB', 5) # returns 4
In 'ABBCB', changing the C to B turns the last four characters into 'BBBB'. A block can never be longer than the string itself, however many changes you have.
0 <= len(s) <= 100,0000 <= k <= 100,000s holds only the letters A to ZReady?
Accept the challenge to start writing. A small timer counts the time this page is in view.
Output appears here.