Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Top Error Message in Last Hour
00:00
5 left

Top Error Message in Last Hour

MediumPython

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):
Interviewer

Your question is Top Error Message in Last Hour. Start with the requirements in the Question tab.

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.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.