Quant Memo
Coding/●●●●●

Resolve colliding buy and sell sweeps

Model each sweep as a signed integer: positive means moving right, negative means moving left, and the magnitude is its size. All sweeps move at the same speed. When a right-mover meets a left-mover, the smaller one is destroyed; if equal, both are destroyed. Same-direction sweeps never collide. Return the surviving sweeps in order.

[5, 10, -5]  -> [5, 10]     # -5 hits 10 and loses
[8, -8]      -> []          # equal magnitudes annihilate
[-2, -1, 1, 2] -> [-2, -1, 1, 2]   # left-movers on the left never meet right-movers

Return the list of surviving sweeps.

Your answer

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

More Coding questions