Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Parse and Count Error Codes

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

Your question is Parse and Count Error Codes. 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 entries as strings, write a function that extracts every error code and returns a formatted summary of code frequencies. A valid error code appears either as ERROR_<digits> anywhere in the line or inside a JSON fragment as "error_code":"ERROR_<digits>". Return a list of strings formatted as "ERROR_404: 3", sorted by descending frequency and then lexicographically by code.

Constraints

  • 1 <= len(logs) <= 10^4
  • 0 <= len(logs[i]) <= 10^3
  • Each line may contain zero or more valid error codes
  • Valid codes match the pattern ERROR_<digits>

Function Signature

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