Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Detect Threats from Service Logs

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

Your question is Detect Threats from Service 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 a list of log lines, parse each line and return a summary of suspicious IPs and slow endpoints. Each log line has the format timestamp ip method path status latency_ms. An IP is suspicious if it has at least failed_threshold responses with status 401 or 403. A path is slow if its average latency is at least slow_threshold milliseconds. Return a dictionary with suspicious IPs sorted by descending failure count, and slow paths sorted lexicographically.

Constraints

  • 1 <= len(logs) <= 10^5
  • Each log line contains exactly 6 space-separated fields
  • 100 <= status <= 599
  • 0 <= latency_ms <= 10^6
  • 1 <= failed_threshold <= 10^5
  • 1 <= slow_threshold <= 10^6

Function Signature

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