Question DSA-HASH-0061
HardWhat is the output of this code?
from collections import defaultdict
a = [1, 2, 3, 2, 1, 2]
k = 3
cnt, s, seen = 0, 0, defaultdict(int)
seen[0] = 1
for x in a:
s += x
cnt += seen[s - k]
seen[s] += 1
print(cnt)
- A.
2
- B.
5
- C.
Sign up free to see the answer and a step-by-step explanation.