bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 359. Logger Rate Limiter

359. Logger Rate Limiter

Leetcode Solutions

Hashtable / Dictionary Approach

  1. Initialize a hashtable to store message-timestamp pairs.
  2. When shouldPrintMessage is called, check if the message is in the hashtable.
    • If the message is not in the hashtable, add it with the current timestamp + 10.
    • If the message is in the hashtable, check if the current timestamp is greater than or equal to the stored timestamp.
      • If true, update the timestamp in the hashtable to the current timestamp + 10.
      • If false, do not update the hashtable and return false.
  3. Return true if the message was added or updated in the hashtable; otherwise, return false.
UML Thumbnail

Queue + Set Approach

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...