Loading...
Loading...
Loading...
A bank lists the net change of n days. Count the blocks of consecutive days whose changes add up to exactly k. The numbers can be negative or zero.
Example
Input
4 7 3 4 7 2
Output
2
The blocks [3, 4] and [7].
Try the problem first. Open one hint at a time.
A block from i to j has sum k when prefix[j + 1] - prefix[i] = k.
Count earlier prefixes equal to prefix - k. Start the Counter with {0: 1}.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor