OHLC bars from a raw trade tape
You are given a day's trade tape as (timestamp_seconds, price, size) tuples, sorted by time, plus a bucket width W in seconds. For each bucket that has trades, build its OHLC bar: the open (first price), high, low, and close (last price).
trades = [(0.5, 100.0, 10), (0.9, 101.0, 30), (1.2, 102.0, 20)]
W = 1.0
-> {0: (100.0, 101.0, 100.0, 101.0), 1: (102.0, 102.0, 102.0, 102.0)}
Return a dict mapping bucket index to (open, high, low, close), in one pass.
Your answer
This one is open-ended. Work it through, then check your reasoning against the full solution.