Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top IPs from Server Logs

MediumPython00:00
I
Practice interviewer
Your interviewer
In session
I
Interviewer

Welcome to the Python screen.

The question is on your right: Top IPs from Server Logs. Read through the requirements first.

Run and submit your code as often as you need. You also have five interviewer messages this session - want to talk through your approach, or are you ready to start coding?

You need to log in / sign up to run or submit.

Problem

Given a list of log file contents, where each file is represented as an array of strings and each string is one web server log line, return the top 10 IP addresses by request count. Treat the IP address as the first whitespace-separated token on each valid line. If multiple IPs have the same count, return them in ascending lexicographic order.

Constraints

  • 1 <= len(log_files) <= 10^3
  • 0 <= total number of log lines across all files <= 10^6
  • 0 <= length of each log line <= 10^3
  • Each valid log line contains the IP address as its first whitespace-separated token

Function Signature

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