Your question is Real-Time Log Metrics Aggregator. 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.
Given a stream of log lines, implement a function that parses each line and returns rolling performance metrics over the last window_seconds. Each valid log line has the format "<timestamp> <service> <latency_ms> <status>", where timestamp is a non-decreasing integer. Ignore malformed lines. For each processed line, output the current metrics for that line's service: total requests in the window, error count (status >= 500), and average latency rounded down.
def aggregate_log_metrics(logs, window_seconds):