Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Real-Time Log Metrics Aggregator

HardPython00:00
Practice interviewer
In session
5 left
00:00

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.

You need to log in / sign up to run or submit.

Problem

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.

Constraints

  • 1 <= len(logs) <= 10^5
  • 1 <= window_seconds <= 10^6
  • Timestamps are non-decreasing integers
  • 0 <= latency_ms <= 10^6
  • 100 <= status <= 599 for valid lines

Function Signature

def aggregate_log_metrics(logs, window_seconds):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output