Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Error IPs in Logs

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

Your question is Top Error IPs in 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 lines logs, where each line is a string containing an IPv4 address and an HTTP status code separated by spaces, return the top 10 IP addresses that generated status code 500. The result should be ordered by descending count of 500 responses, and for ties, by ascending IP string.

Constraints

  • 1 <= len(logs) <= 2 * 10^5
  • Each log line has the form "<ip> <status>"
  • status is a 3-digit string
  • Return at most 10 results

Function Signature

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