A control tower relays status messages, but throttles repeats: a given message text may be relayed at most once per cooldown window of w time units. A message is ALLOWed if it has never been relayed, or if at least w units have passed since it was last relayed (that is, the current time is greater than or equal to its last-allowed time plus w). Otherwise it is BLOCKed. Every ALLOWed message updates its last-allowed time to the current time; a BLOCKed message does not.
Line 1: two integers q and w.
Next q lines: each is t msg, a timestamp t and a message text msg (lowercase letters and digits, no spaces). Timestamps are given in non-decreasing order.
For each of the q messages, in order, print ALLOW or BLOCK on its own line.
Example 1
Input
5 3 0 login 1 login 3 login 3 logout 6 login
Expected
ALLOW BLOCK ALLOW ALLOW ALLOW
Explanation
With w=3: login at 0 is ALLOWed. login at 1 is within cooldown so BLOCK. login at 3 (>= 0+3) is ALLOWed. logout at 3 is new so ALLOW. login at 6 (>= 3+3) is ALLOWed.
Example 2
Input
3 5 0 alpha 2 beta 4 alpha
Expected
ALLOW ALLOW BLOCK
Explanation
With w=5: alpha at 0 is ALLOWed, beta at 2 is ALLOWed, and alpha at 4 is still within 5 units of its last relay at 0, so BLOCK.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →