Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Logger Rate Limiter

Easy

Topics
Hash TableDesignData Stream

Design a logger that limits each unique message to being printed at most once every 10 seconds. Implement Logger() and shouldPrintMessage(timestamp, message), which returns true if the message should be printed at the given timestamp (in seconds), and false otherwise. A message printed at time t may next be printed at t + 10 or later.

Example 1

Input:  operations = ["Logger","shouldPrintMessage","shouldPrintMessage","shouldPrintMessage","shouldPrintMessage","shouldPrintMessage","shouldPrintMessage"], values = [[],[1,"foo"],[2,"bar"],[3,"foo"],[8,"bar"],[10,"foo"],[11,"foo"]]
Output: [null,true,true,false,false,false,true]

Constraints

  • 0 <= timestamp <= 10^9
  • Every timestamp is greater than or equal to the previous.
  • At most 10^4 calls.
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access