Question DSA-TP-0065
HardWhat is the output of this code?
s = "AABABBA"
k = 1
cnt, l, best, top = {}, 0, 0, 0
for r, ch in enumerate(s):
cnt[ch] = cnt.get(ch, 0) + 1
top = max(top, cnt[ch])
if r - l + 1 - top > k:
cnt[s[l]] -= 1; l += 1
best = max(best, r - l + 1)
print(best)
- A.
7
- B.
5
- C.
Sign up free to see the answer and a step-by-step explanation.