← Questions
Message latency from send and receive logs
0
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Amazon's technical phone screen, last asked Mar 2026. It tests csv, parsing and hash maps.
Two machines exchange messages. One CSV log lists when machine A sent each message; another lists when machine B received each one. Both clocks are synchronized. A message is identified by its type and id. For every message that appears in both logs, output its latency, receive time minus send time.
Interface
Unless you agree on a different interface with the interviewer, assume:
-
latencies(send_rows: Iterable[str], receive_rows: Iterable[str]) -> list[str]— each log starts with the headermessage_type,id,synchronized_timestamp; returns rowsmessage_type,id,latencysorted by type, then id. Messages in only one log are left out.
Example
send log: receive log:
message_type,id,synchronized_timestamp message_type,id,synchronized_timestamp
altitude,0,222 altitude,0,223
altitude,2,224 altitude,1,225
altitude,1,223 altitude,2,226
altitude,3,230
latencies(...) -> ["altitude,0,1", "altitude,1,2", "altitude,2,2"] # altitude 3 was never received
send: temp,0,100 altitude,1,50 temp,1,120 status,0,70
recv: temp,0,105 status,0,72 altitude,1,55 altitude,2,60
latencies(...) -> ["altitude,1,5", "status,0,2", "temp,0,5"]
Constraints
- Up to 10^5 rows per log; ids and timestamps fit in 32-bit integers.
- Within a log, each (type, id) appears once. Ids increase within a type.
Clarifying questions
- What should happen to messages found in only one log: skip, or report them?
- Can a message be received before it was sent (negative latency)?
- Do the files fit in memory? Are they sorted?
- Is the output order important?
What a strong answer covers
- Reading line by line, skipping the header, parsing three fields and validating them.
- A map from
(type, id)to send time, then one pass over the receive log. - Handling unmatched, duplicate and malformed rows explicitly.
- O(n + m) time plus sorting the output; tests with each edge case.
Follow-ups
- Report the average and p99 latency per message type.
- The logs are too big for memory but sorted by id within each type: merge them in one streaming pass.
- The clocks are not synchronized: how would you estimate the offset?
Where it's asked
- Amazon · Technical phone screen · Last asked Mar 202660 min · Live coding in a shared editor that does not run code, plus Leadership Principles questions · No AI
What it tests
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding
