Your question is Sliding Window and Query Logic. 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.
Datadog log analytics needs to evaluate simple log filters and aggregate numeric fields over time ranges. Given timestamp-sorted logs and independent queries, return the sum of matching log values for every inclusive interval.
A log matches a query when its service equals the query service and its numeric status is at least min_status. Each query contains intervals sorted by increasing start time, with no overlap.
Implement query_log_interval_sums(logs, queries), where logs is a list of dictionaries with integer timestamp, string service, integer status, and integer value fields. queries is a list of dictionaries containing a string service, integer min_status, and an intervals list of [start, end] integer pairs. Return one list of sums per query, preserving query and interval order. Both interval endpoints are inclusive.
def query_log_interval_sums(logs, queries):