A fundraiser logs n donation entries in order; each entry is an integer amount (a negative amount represents a reversed or refunded donation). Given a target t, count how many contiguous runs of consecutive entries have amounts summing to exactly t. Two runs are different if they start or end at different positions, even if their amounts are identical.
Line 1: an integer n.
Line 2: n space-separated integers, the donation amounts in order.
Line 3: an integer t, the target sum.
A single integer: the number of contiguous runs whose sum equals t.
Example 1
Input
4 1 -1 1 -1 0
Expected
4
Explanation
The runs summing to 0 are [1,-1], [-1,1], [1,-1] (the last pair), and the whole [1,-1,1,-1]; that is 4 runs.
Example 2
Input
3 2 2 2 4
Expected
2
Explanation
Two adjacent pairs sum to 4: positions 1..2 and positions 2..3.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →