Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Detect Anomalous Infrastructure Log Events

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

Your question is Detect Anomalous Infrastructure Log Events. 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, identify anomalous events by counting how many times each (service, action) pair appears per minute. Each log line has the format "timestamp service action status", where timestamp is YYYY-MM-DDTHH:MM:SS. Return all (minute, service, action) groups whose count is strictly greater than a given threshold, sorted by minute, then service, then action.

Constraints

  • 1 <= len(logs) <= 10^5
  • Each log line contains exactly 4 space-separated fields
  • 0 <= threshold <= 10^5
  • Invalid log lines should be ignored

Function Signature

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