Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Aggregate Error Codes from Logs

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

Your question is Aggregate Error Codes from Logs. 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 an array of log lines logs and an array of target error codes target_codes, return a dictionary mapping each target error code to the number of times it appears in the logs. A valid error code appears in the form ERROR_CODE=<code> within a log line. Ignore malformed lines and codes not present in target_codes.

Constraints

  • 1 <= len(logs) <= 10^5
  • 1 <= len(target_codes) <= 10^4
  • 1 <= len(logs[i]) <= 10^3
  • Target codes are unique strings
  • A valid code appears as ERROR_CODE=<code> and ends at the next space or end of line

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