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
Sliding Window Logger Design
00:00
5 left

Sliding Window Logger Design

MediumPython

Problem

Design the logic for a logger (solved with a sliding window), with a follow-up needing a different algorithm.

Asked in the onsite DSA 3 stage.

Implement should_print_message(timestamp, message, last_seen). Return True if the message has not been printed during the previous 10 seconds, otherwise return False. When returning True, update last_seen with the message's timestamp. Timestamps arrive in nondecreasing order. Discuss a follow-up where timestamps may arrive out of order and explain why the original approach is insufficient.

Constraints

  • Timestamps are nonnegative integers.
  • Timestamps passed to the main function are in nondecreasing order.
  • Messages are nonempty strings.
  • The cooldown interval is exactly 10 seconds.
  • The state dictionary contains only previously accepted messages.

Function Signature

def should_print_message(timestamp, message, last_seen):
Interviewer

Your question is Sliding Window Logger Design. 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.