Problem · Array
Message Latencies from CSV Logs
Learn this problemProblem statement
You receive two in-memory CSV logs for the same set of messages:
sentLogs[i]has the form"timestamp,messageId"for a send event.receivedLogs[i]has the same form for a receive event.
Each message ID appears exactly once in each log, but the two arrays may list messages in different orders. The latency of a message is its receive timestamp minus its send timestamp.
Return an integer array where answer i is the latency of the message described by sentLogs[i].
Function
messageLatencies(sentLogs: String[], receivedLogs: String[]) → int[]Examples
Example 1
sentLogs = ["100,m1","105,m2"]receivedLogs = ["112,m2","109,m1"]return = [9,7]The latencies are 109 - 100 = 9 for m1 and 112 - 105 = 7 for m2, in sent-log order.
Example 2
sentLogs = ["7,job9"]receivedLogs = ["20,job9"]return = [13]The only message takes 13 time units.
Example 3
sentLogs = ["0,a","20,b","15,c"]receivedLogs = ["18,c","20,a","25,b"]return = [20,5,3]Looking up receive timestamps by ID produces latencies 20, 5, and 3.
Constraints
1 <= sentLogs.length = receivedLogs.length <= 100000.- Each row contains one integer timestamp, one comma, and one nonempty alphanumeric message ID.
- Every message ID appears exactly once in each array.
0 <= sendTimestamp <= receiveTimestamp <= 10^9for every message.