Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Five Frequent Error Logs

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

Your question is Top Five Frequent Error 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

In Meta infrastructure systems, engineers often need to summarize large volumes of Scuba-style server logs. Given a list of log lines, return the top 5 most frequent error messages.

A log line is considered an error message only if it starts with the prefix "ERROR: ". The message is the substring after that prefix. Count identical messages together and return up to 5 messages ordered by descending frequency. If two messages have the same frequency, return them in lexicographically ascending order.

Formal Specification

Implement a function that takes a list of strings logs and returns a list of strings.

  • Input: logs, a list of log lines
  • Output: a list containing up to 5 error messages

Ignore all non-error log lines.

Constraints

  • 1 <= len(logs) <= 10^5
  • 0 <= len(logs[i]) <= 200
  • Each log line is an ASCII string
  • A valid error line starts exactly with "ERROR: "
  • Return at most 5 messages
  • If fewer than 5 distinct error messages exist, return all of them

Function Signature

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