DIY: Logger Rate Limiter
Solve the interview question "Logger Rate Limiter" in this lesson.
We'll cover the following
Problem statement
Design a logger system that receives a stream of messages and their timestamps. Each message should be printed if and only if it is not printed in the last 5
seconds.
Input
The input will be a stream of messages and their timestamps in the following format:
func(timestamp, message)
Output
The output will be a Boolean variable in the form of either true
or false
.
Coding exercise
Implement the should_print_message(obj, timestamp, message)
function, where obj
is the struct object, timestamp
is the time of arrival of the message and message
is the text which you need to store. The function returns true
if the message will be printed in the given timestamp. Otherwise, it returns false
. It is possible that several messages arrive at roughly the same time.
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.