Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Parse and Aggregate Log Errors

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

Your question is Parse and Aggregate Log Errors. 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

Adecco One emits application logs in a pipe-delimited format. Given an array of log lines, parse each line, keep only ERROR events from selected services within a half-open time interval, and aggregate the number of occurrences for each error code.

Each valid log line has this format:

timestamp|service|level|error_code|message

The timestamp is an integer, and the message may contain additional pipe characters. Return a dictionary mapping each matching error code to its count. If no lines match, return an empty dictionary.

Formal Specification

Implement aggregate_error_counts(logs, allowed_services, start_time, end_time).

  • logs is a list of strings.
  • allowed_services is a list of service names.
  • start_time is inclusive and end_time is exclusive.
  • A line matches only when its timestamp is in the interval, its service is allowed, and its level is exactly ERROR.
  • All input log lines are valid and contain at least five fields.

Constraints

  • 1 <= len(logs) <= 10^5
  • Each log line contains at least five pipe-delimited fields
  • 0 <= timestamp <= 10^9
  • 1 <= len(error_code) <= 32
  • The total number of characters across all log lines is at most 10^7

Function Signature

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