Logger Rate Limiter
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
A logging service is flooded with repeated messages. Each distinct message text may be printed at most once every **10 seconds**: if a message is printed at time t, the same text must be suppressed at every time strictly before t + 10.
Implement:
- Logger() creates the limiter.
- shouldPrintMessage(timestamp, message) returns true if message should be printed at timestamp (and records that it was printed), otherwise returns false.
Suppressed messages do **not** reset the 10-second window — only printed ones do. Timestamps are integer seconds and arrive in non-decreasing order; several messages may share a timestamp.
Examples
Constraints
- 0 <= timestamp <= 10^9
- Timestamps are non-decreasing across calls.
- 1 <= message.length <= 30
- At most 10^4 calls are made.
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.