Code RoomClock offset bounds
EasyPrep Room Coding #4833

Clock offset bounds

CodingNetworking & APIsDistributed systemsEntry–Mid~16 min

A monitoring agent works out how far a server's clock sits from its own. For probe i the agent stamps client_send_ms[i] as the request leaves, the server stamps server_recv_ms[i] when it lands and server_send_ms[i] when the reply leaves, and the agent stamps client_recv_ms[i] when the reply arrives. The first and last readings come from the agent's clock, the middle two from the server's, and the four lists share a length. Every hop takes zero or more milliseconds, and neither clock is stepped during the run. Call the offset the server clock minus the client clock. Return the tightest range of offsets that fits every probe, as a two element list with the lower bound first. Return an empty list when no single offset fits them all, and when no probes are given.

Implement
clock_offset_bounds(client_send_ms: list[int], server_recv_ms: list[int], server_send_ms: list[int], client_recv_ms: list[int]) → list[int]
Examples
in[[1000],[1520],[1521],[1040]]out[481,520]
in[[100,300],[640,845],[641,846],[140,340]]out[506,540]
in[[10,20],[1010,1500],[1010,1500],[30,40]]out[]
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.

0:00 of about 16 min
InputExpectedGot
[[1000],[1520],[1521],[1040]][481,520]not run yetsample
[[100,300],[640,845],[641,846],[140,340]][506,540]not run yetsample
[[10,20],[1010,1500],[1010,1500],[30,40]][]not run yetsample