Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Aggregate Error Codes by Timestamp

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

Your question is Aggregate Error Codes by Timestamp. 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 list of log lines logs and a list of target error codes target_codes, write a function that parses each line and returns a mapping from timestamp to error-code counts. Each valid log line has the format TIMESTAMP|LEVEL|CODE|MESSAGE. Only count lines whose CODE is in target_codes. Ignore malformed lines.

Constraints

  • 1 <= len(logs) <= 10^5
  • 1 <= len(target_codes) <= 10^3
  • Each log line is a string of length 1 to 10^4
  • Valid lines contain exactly 4 fields separated by |
  • Return timestamps in the order they first appear in valid matching lines

Function Signature

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