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