NNetflix·DSASeniorTechnical Phone Screen
Logger Rate Limiter
Problem
Design a logger that receives a stream of messages with timestamps and prints each unique message at most once every 10 seconds.
Example
shouldPrint(1,"foo") -> true
shouldPrint(2,"foo") -> false
shouldPrint(11,"foo") -> true
Constraints
- Timestamps arrive in non-decreasing order
Approach
Hash map of message -> next-allowed timestamp. Netflix favors clean design and trade-off talk over speed.
added 6 days ago