Range PnL queries with prefix sums
You have a desk's daily PnL for the year and must serve many queries of the form "total PnL from day l through day r inclusive" (0-indexed).
pnl = [3, -1, 4, -2, 5]
query(1, 3) -> 1 # -1 + 4 - 2
query(0, 4) -> 9
Answer each query in after preprocessing. Summing the slice per query is per query, too slow for millions of queries.
Your answer
This one is open-ended. Work it through, then check your reasoning against the full solution.