Code Room
CodingMediumcod-g1095
Subject Lamport timestamp assignment over distributed eventsLevel Mid–Senior~28 minCommon in Distributed systems interviewsIndustries Technology

Question

Assign Lamport logical timestamps to a sequence of events across processes. Each event is [proc, type, arg]. For type 'local', the process increments its clock by 1. For type 'send', the process increments its clock by 1 and the message is tagged with that clock; `arg` is a message id. For type 'recv', the process sets its clock to max(local_clock, received_timestamp) + 1; `arg` is the message id being received (its send must appear earlier in the list). Every process starts at clock 0. Return the list of assigned Lamport timestamps, one per event in input order.

Implement
lamport_timestamps(events: list[list]) → list[int]
Examples
in[[["P1","local",null],["P1","send","m1"],["P2","recv","m1"]]]out[1,2,3]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.