Logger Rate Limiter
Easy · Hashing · about 10 minutes
Asked at Google, Amazon, Roblox, Microsoft, Uber.
Messages arrive at a logger along with a timestamp in seconds; timestamps never go backwards. To cut down on noise, the same message text may only be printed once per 10 seconds: printing it at time t silences it until time t + 10.
Implement Logger:
Logger()sets up an empty logger.shouldPrintMessage(timestamp, message)answers whether this message may be printed now. If yes, it
remembers the print and returns true; otherwise it returns false.