Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Error Message in Last Hour

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

Your question is Top Error Message in Last Hour. 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

Salesforce Event Monitoring produces a time-ordered stream of error logs. Given the logs received up to a specified time, return the most frequent error message from the inclusive one-hour window ending at that time.

Messages are compared exactly, including capitalization and whitespace. If multiple messages have the same highest frequency, return the lexicographically smallest message. Return an empty string when the window contains no logs.

Formal Specification

Implement most_frequent_error(logs, current_time).

  • logs is a list of two-element lists, where each entry is [timestamp, message].
  • timestamp is an integer number of seconds, and message is a string.
  • Logs are sorted by nondecreasing timestamp and contain no entries after current_time.
  • The one-hour window includes timestamps in [current_time - 3600, current_time].
  • Return a string containing the selected error message, or "" if no log is in the window.

Constraints

  • 0 <= len(logs) <= 10^5
  • 0 <= timestamp <= 10^12
  • 0 <= len(message) <= 200
  • logs is sorted by nondecreasing timestamp
  • All timestamps are less than or equal to current_time
  • At most 10^5 distinct messages occur

Function Signature

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