K-Second Message Suppression
Problem statement
For each chronological (timestamp, message) pair, return whether the message is accepted. The same message may be accepted again only when at least k seconds have passed since its most recent accepted occurrence.
A suppressed occurrence does not reset the timer.
Function
shouldAcceptMessages(timestamps: int[], messages: String[], k: int) → boolean[]Examples
Example 1
timestamps = [1,2,3,8,11]messages = ["a","b","a","a","a"]k = 10return = [true,true,false,false,true]The final a is ten seconds after the first accepted a.
Example 2
timestamps = [1,1]messages = ["x","y"]k = 5return = [true,true]Different messages are independent.
Constraints
- The arrays have equal length up to
100000. - Timestamps are non-decreasing.
0 <= k <= 10^9.
Source note: Author-written prompt excerpt retained for source fidelity.