FastPrepMessage Latencies from CSV Logs
Problems/Message Latencies from CSV Logs

Message Latencies from CSV Logs

Amazon logoAmazon● EasyINTERNONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report explicitly asks candidates to calculate message latency from two CSV logs and allows a LeetCode-style solution without file parsing. It omits the exact schema and return order; this practice contract uses timestamp,messageId rows and aligns answers to sentLogs, matching the reported task at about 85%.

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^9 for every message.

More Amazon problems

  • Count Adjacent Symbol Pairs for BPEONSITE INTERVIEW · Seen Nov 2026
  • First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
See Amazon hiring insights
Saved
public int[] messageLatencies(String[] sentLogs, String[] receivedLogs) {
  // write your code here
}
Checking account…