Get Message Status
Problem statement
A messaging service receives n messages in time order. Message i has the text messages[i] and arrives at time timestamps[i].
The service must never deliver the same text twice within k time units. Process the messages in input order. Message i is delivered unless an earlier delivered message has the same text and a time t with timestamps[i] - t < k. In that case it is dropped.
A dropped message does not count as a delivery, so it never blocks a later message. Messages with the same timestamp are still handled one by one in input order.
Return a boolean array whose element i is true if message i is delivered and false if it is dropped.
Function
getMessageStatus(timestamps: int[], messages: String[], k: int) → boolean[]Examples
Example 1
timestamps = [1,4,6,9,10,12]messages = ["hello","bye","bye","bye","hello","hello"]k = 5return = [true,true,false,true,true,false]- Time 1:
"hello"has not been delivered, so it is delivered. - Time 4:
"bye"is delivered. - Time 6: the last delivered
"bye"was at time 4, and6 - 4 = 2is less thank = 5, so this one is dropped. - Time 9:
9 - 4 = 5, which is not less than5, so it is delivered. The dropped copy at time 6 does not count. - Time 10:
10 - 1 = 9, so"hello"is delivered again. - Time 12:
12 - 10 = 2is less than5, so it is dropped.
Example 2
timestamps = [3,3,3,4]messages = ["a","b","a","a"]k = 1return = [true,true,false,true]The first three messages arrive at the same time and are handled in input order. The second "a" is 0 time units after the first one, which is less than k = 1, so it is dropped. The last "a" is 4 - 3 = 1 unit after the delivered one, so it is delivered.
Example 3
timestamps = [0,999999999,1000000000]messages = ["x","x","x"]k = 1000000000return = [true,false,true]The second "x" is 999999999 units after the first, which is less than k, so it is dropped. The third is exactly k units after the first delivered one, so it is delivered.
Constraints
1 <= n <= 2000, wheren == timestamps.length == messages.length0 <= timestamps[i] <= 10^9, andtimestampsis sorted in non-decreasing order.1 <= k <= 10^91 <= messages[i].length <= 10, andmessages[i]contains only lowercase English letters.