Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Get started
Log Analysis for Suspicious Activity
00:00
5 left

Log Analysis for Suspicious Activity

MediumPython

Problem

Write a function to analyze log files for suspicious activity.

Implement analyze_logs(logs), where logs is a list of dictionaries containing integer timestamp, string ip, and string event fields. Return sorted IP addresses with at least three login_failed events occurring within any 300-second inclusive window; ignore other events. Examples: timestamps [0, 150, 300] return the IP, while [0, 301, 602] does not. Constraints: 0 <= len(logs) <= 100, timestamps are nonnegative integers, and each log has all required fields.

Constraints

  • 0 <= len(logs) <= 100
  • Each log contains integer timestamp, string ip, and string event fields
  • Timestamps are nonnegative integers
  • Only events equal to login_failed are considered
  • A 300-second window is inclusive at both ends

Function Signature

def analyze_logs(logs):
Interviewer

Your question is Log Analysis for Suspicious Activity. Start with the requirements in the Question tab.

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.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.