Question DSA-HASH-0044
MediumWhat is the output of this code?
a = [1, 1, 1]
k = 2
count, s, seen = 0, 0, {0: 1}
for x in a:
s += x
count += seen.get(s - k, 0)
seen[s] = seen.get(s, 0) + 1
print(count)
- A.
1
- B.
2
- C.
0
- D.
3
Sign up free to see the answer and a step-by-step explanation.