Stretches With an Exact Total
Medium · Stretches With an Exact Total
The array `changes` holds the daily changes of an account balance: a positive number is a deposit, a negative one is a withdrawal. An analyst wants periods of consecutive days over which the balance moved by exactly `total` (a negative `total` means it went down). Count the non-empty stretches of consecutive elements of `changes` whose sum equals `total`. Two stretches are different if they start or end at different positions.…
Solve the problem →