Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top IPs from Server Logs

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

Your question is Top IPs from Server 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 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