Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Parse and Aggregate Log Errors
00:00
5 left

Parse and Aggregate Log Errors

EasyPython

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):
Interviewer

Your question is Parse and Aggregate Log Errors. Start with the requirements in the Question tab.

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.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.