Skip to main content

Logger Rate Limiter

Easy
Data Structures and Algorithms
Editorial
Topics:
Hash Table
Design
Data Stream

You are designing a logger system that receives a stream of messages, each accompanied by a timestamp in seconds. Implement the Logger class:

  • Logger() initializes the logger object.
  • bool shouldPrintMessage(int timestamp, string message) returns true if the message should be printed at the given timestamp, otherwise returns false.

A message should only be printed if it has not been printed in the last 10 seconds (including the current timestamp). Each call to shouldPrintMessage will have a non-decreasing timestamp.

Constraints:

  • 0 <= timestamp <= 10^9
  • 1 <= message.length <= 30
  • At most 10^4 calls will be made to shouldPrintMessage.

Return true if the message should be printed at the given timestamp, otherwise return false.

Need help or want more practice?

Practise in an interviewGet AI Coach help