Design an in-memory NotificationFilter to filter duplicate notifications. Each notification has a UUID string called notificationId.
A notification is a duplicate if the same ID arrived less than 600 seconds earlier. Compare against its most recent arrival, including rejected duplicates. Every arrival updates that ID's last-seen time.
NotificationFilter()
boolean shouldSend(String notificationId, long arrivalTime)
notificationId: the notification's ID.arrivalTime: its arrival time in seconds. Use this input instead of the system clock.false for a duplicate or true otherwise.null.0 ≤ arrivalTime ≤ 1,000,000,000,000.O(N) memory, where N is the number of distinct IDs seen within the current 600-second window.O(1) or O(log N) processing time per call, including cleanup.Create a new filter with NotificationFilter(), then make these calls in order:
shouldSend(notificationId = "748e219a-4be6-4c2c-972b-1a63c89d425f", arrivalTime = 20) returns true: this ID is new.shouldSend(notificationId = "748e219a-4be6-4c2c-972b-1a63c89d425f", arrivalTime = 300) returns false: only 280 seconds have passed.shouldSend(notificationId = "748e219a-4be6-4c2c-972b-1a63c89d425f", arrivalTime = 620) returns false: only 320 seconds have passed since the latest arrival.shouldSend(notificationId = "748e219a-4be6-4c2c-972b-1a63c89d425f", arrivalTime = 1220) returns true: exactly 600 seconds have passed since the latest arrival.Create a new filter with NotificationFilter(), then make these calls in order:
shouldSend(notificationId = "748e219a-4be6-4c2c-972b-1a63c89d425f", arrivalTime = 50) returns true: this ID is new.shouldSend(notificationId = "b913d7e4-2c86-42da-a3e1-f67805bc192d", arrivalTime = 50) returns true: this is a different ID.shouldSend(notificationId = "748e219a-4be6-4c2c-972b-1a63c89d425f", arrivalTime = 50) returns false: the same ID already arrived at this time.