Count flat PnL segments
Asked at DE Shaw, Millennium
Given per-trade PnL values, count how many contiguous segments net to exactly zero, stretches where gains and losses perfectly cancel.
pnl = [1, -1, 2, -2]
-> 3 # [1,-1], [2,-2], and [1,-1,2,-2]
Return the number of contiguous zero-sum segments. Aim for .
Your answer
This one is open-ended. Work it through, then check your reasoning against the full solution.