Your question is Optimizing Data Retrieval. 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.
A Zensar delivery analytics pipeline stores events sorted by timestamp. Each event contains a timestamp and its payload size in bytes. Given many time-range retrieval requests, return the total payload size of events whose timestamps fall within each inclusive range.
The dataset is already sorted by timestamp. Design an efficient function that avoids scanning the full dataset for every request.
Implement range_payload_totals(events, queries).
events is a list of [timestamp, payload_size] pairs sorted in nondecreasing timestamp order.queries is a list of [start_time, end_time] pairs.start_time <= timestamp <= end_time.0.def range_payload_totals(events, queries):