Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Detect Anomalous IP Request Bursts

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

Your question is Detect Anomalous IP Request Bursts. 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 set of target IP addresses target_ips, an integer window size window_seconds, and an integer threshold max_requests, write a function that parses the logs, counts requests for the target IPs, and returns the IPs that have any time window of length window_seconds containing more than max_requests requests. Each valid log line has the format "<timestamp> <ip>", where timestamp is an integer number of seconds.

Constraints

  • 1 <= len(logs) <= 10^5
  • 1 <= len(target_ips) <= 10^4
  • 0 <= timestamp <= 10^9
  • Log lines may be invalid and should be ignored
  • Output IPs should be returned in sorted order

Function Signature

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