Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Parse Logs for Error Reporting

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

Your question is Parse Logs for Error Reporting. 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

Daimler Truck North America's Detroit Connect telemetry services emit pipe-delimited log lines. Write a function that parses the logs, aggregates ERROR entries by service and error code, and reports only groups meeting a minimum occurrence count.

Formal Specification

Implement aggregate_error_logs(logs, min_count). Each string in logs has this format:

timestamp|host|service|level|code|message

Return a list of dictionaries. Each dictionary must contain:

  • service: the service name
  • code: the error code
  • count: the number of matching ERROR entries
  • hosts: sorted unique hosts that produced the error

Include only groups where count >= min_count. Sort the result by descending count, then ascending service, then ascending code. Inputs contain valid records with exactly six fields, and messages may contain additional pipe characters after the fifth separator.

Constraints

  • 1 <= len(logs) <= 10^5
  • 1 <= min_count <= len(logs)
  • Every log line contains exactly six logical fields
  • Messages may contain additional pipe characters
  • Service and code names contain no pipe characters

Function Signature

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