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
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess 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
Build my plan
Log Analysis for Top 5 IPs
00:00
5 left

Log Analysis for Top 5 IPs

MediumPython

Problem

Vercel access logs contain one request per line in the format timestamp ip status, separated by single spaces. Write a function that identifies the IP addresses generating the most server errors.

Count a request as an error when its HTTP status code is in the inclusive range 500 through 599. Return up to five IP addresses, ordered by decreasing 5xx request count. If multiple IPs have the same count, order those IPs lexicographically. Ignore the timestamp after parsing it, and assume every input line is valid.

Formal Specification

  • Input: logs, a list of non-empty strings. Each string has the format timestamp ip status, where timestamp contains no spaces, ip is an IPv4 or IPv6 address, and status is an integer HTTP status code.
  • Output: A list of at most five strings containing the qualifying IP addresses. An IP appears once, even if it triggers multiple errors.

Constraints

  • 0 <= len(logs) <= 10^6
  • Each line contains exactly three space-separated fields
  • Status codes are integers from 100 through 599
  • Return no more than five IP addresses

Function Signature

def top_5xx_ips(logs):
Interviewer

Your question is Log Analysis for Top 5 IPs. 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.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.