Message Latencies from CSV Logs
Updated
Problem 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.
More Amazon Onsite Interview questions
- Number of IslandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Cheapest Flights Within K StopsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Dungeon GameONSITE INTERVIEW · Seen Nov 2026
- Integer BreakONSITE INTERVIEW · Seen Nov 2026
- LFU CacheONSITE INTERVIEW · Seen Nov 2026
- LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Count Adjacent Symbol Pairs for BPEONSITE INTERVIEW · Seen Nov 2026
- First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
- Deep Merge with a Conflict ResolverAutodesk · ONSITE INTERVIEWAutodesk interview questions
- Linked Merchants Within Two HopsStripe · PHONE SCREENStripe interview questions
- Insert an Employee into an Organization HierarchyWaymo · PHONE SCREENWaymo interview questions
- Machine Message RouterOpenAI · PHONE SCREENOpenAI interview questions
- Map and Accumulate Learning QueriesPalantir · ONSITE INTERVIEWPalantir interview questions
- Filter Pins by Excluded IDsPinterest · ONSITE INTERVIEWPinterest interview questions
- Longest Dictionary Word from Nine LettersGoogle · ONSITE INTERVIEWGoogle interview questions
- K-Second Message SuppressionMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Logger Rate LimiterAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions
Amazon interview experiences
- Amazon SWE OA with AI Coding: 1 Experience
- Amazon SWE Intern Phone Screen Interview Experience: 1 Experience
- Amazon New Grad SDE I OA and Virtual Onsite: 1 Experience
- Amazon BIE Intern SQL and Interview Questions: 17 Experiences
- Amazon Experienced SWE AI-Assisted Debugging OA: 1 Experience
- Amazon SDE II (L5) Interview Questions: 5 Experiences