Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Count Repeated IP Addresses

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

Your question is Count Repeated IP Addresses. 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 as strings, return the IP address that appears most often. Each valid line starts with an IPv4 address followed by a space and the rest of the message. Ignore malformed lines that do not start with a valid IPv4 address. If multiple IPs have the same highest count, return the lexicographically smallest one. If no valid IP exists, return an empty string.

Constraints

  • 1 <= len(logs) <= 10^4
  • 0 <= len(logs[i]) <= 200
  • Each line is a string
  • A valid IPv4 address has exactly 4 numeric parts
  • Each IPv4 part must be in the range 0 to 255

Function Signature

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