Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Parse Logs for Error Alerts

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

Your question is Parse Logs for Error Alerts. 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, a list of error substrings patterns, and an integer window_size, write a function that scans the logs in order and returns alert payloads for matching errors. A line should produce an alert if it contains any pattern and includes a valid JSON object with keys service, code, and message. Deduplicate alerts so the same (service, code, message) is emitted at most once within the last window_size matching alerts.

Constraints

  • 1 <= len(logs) <= 10^5
  • 1 <= len(patterns) <= 20
  • 0 <= window_size <= 10^4
  • 1 <= len(logs[i]) <= 10^4
  • JSON objects, when present, appear within a single log line

Function Signature

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