Company: Microsoft SDE2_23june
Difficulty: medium
A messaging app needs to prevent sending duplicate messages. If a message with the same text was already delivered in the last k seconds, the new one is considered a duplicate and dropped. Given a list of messages with their arrival times, return whether each message should be delivered ( true ) or marked as a duplicate ( false ). Example 1 Suppose the number of messages (n) = 6, timestamps = [1, 4, 6, 9, 10, 14], messages = ["Hello", "Bye", "Bye", "Bye", "Bye", "Hello"], and k = 8. Timestamp Message request Last Matching Message Delivered Delivered 1 Hello - true 4 Bye - true 6 Bye 4 false 9 Bye 4 false 10 Bye 4 true 14 Hello 1 true The output array should be ["true", "true", "false", "false", "true", "true"] Example 2 timestamps = [1, 1, 1, 1] messages = ["message-2", "message-2", "message-3", "message-2"] k = 5 Only the second message is dropped. The output array is ["true", "false", "true", "true"] Constraints 1 ≤ n ≤ 10 5 1 ≤ messages[i].length ≤ 15 1 ≤ timestamp[i] ≤ 10 6 It is g