Question DSA-TP-0063
HardWhat is the output of this code?
s = "abaccc"
k = 2
from collections import Counter
c, l, best = Counter(), 0, 0
for r, ch in enumerate(s):
c[ch] += 1
while len(c) > k:
c[s[l]] -= 1
if c[s[l]] == 0:
del c[s[l]]
l += 1
best = max(best, r - l + 1)
print(best)
- A.
4
- B.
5
- C.
6
- D.
3
Sign up free to see the answer and a step-by-step explanation.