Easy · System Design
Logger Rate Limiter
Given shouldPrintMessage(timestamp, message) calls in non-decreasing timestamp order, return for each call whether the message prints. It prints unless the same message last printed at a time t with timestamp < t + 10, and only printed calls update that time.
Examples
Example 1
{
"ops": [
{"ts": 1, "msg": "foo"},
{"ts": 5, "msg": "bar"},
{"ts": 8, "msg": "foo"},
{"ts": 9, "msg": "foo"}
]
}Output: true, true, false, false
Example 2
{
"ops": [
{"ts": 1, "msg": "foo"},
{"ts": 10, "msg": "foo"},
{"ts": 11, "msg": "foo"},
{"ts": 11, "msg": "bar"},
{"ts": 20, "msg": "foo"},
{"ts": 21, "msg": "foo"}
]
}Output: true, false, true, true, false, true
Rebuild it in the studio
Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.