A courier logs the number of parcels delivered on each stop in parcels (values may be negative when parcels are collected instead). Count the non-empty contiguous stretches of stops whose parcel total is exactly k.
Examples
Input: parcels = [2, -1, 3, 1, 2], k = 3
Output: 3
Explanation: [3], [-1, 3, 1] and [1, 2] each total 3.
Input: parcels = [0, 0], k = 0
Output: 3
Explanation: [0], [0] and [0, 0].
Constraints
1 <= len(parcels) <= 10**5-1000 <= parcels[i] <= 1000,-10**7 <= k <= 10**7- Target complexity: O(n) time. Enumerating every stretch is too slow for the largest tests.
Goals
- Translate 'sum equals k' into 'prefix minus k was seen before'
- Count matches with a frequency map in one pass