Quant Memo
Coding/●●●●●

Count day-ranges whose PnL equals a target

You have a desk's daily PnL for the year. Count how many contiguous day-ranges sum to exactly k.

pnl = [3, -1, 4, -2, 5], k = 6
-> 2           # [3, -1, 4] and [-1, 4, -2, 5]

Count all such ranges in O(n)O(n).

Your answer

This one is open-ended. Work it through, then check your reasoning against the full solution.

More Coding questions