Your question is Sliding Window Trading Volume. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Akuna Capital's market-data feed provides trades in chronological order. Given each trade's timestamp and volume, find the maximum total volume traded during any fixed-duration time window.
Use a sliding-window technique and minimize auxiliary memory. A window is half-open, [start, start + window_seconds), so a trade exactly at start + window_seconds is excluded. Because volumes are nonnegative, it is sufficient to evaluate windows whose start aligns with a trade timestamp.
Implement max_window_volume(timestamps, volumes, window_seconds).
timestamps is a list of nondecreasing integers representing seconds.volumes is a list of nonnegative integers, where volumes[i] belongs to timestamps[i].window_seconds is a positive integer.timestamps is empty, return 0.def max_window_volume(timestamps, volumes, window_seconds):