Code RoomRead repair stale replicas
MediumPrep Room Coding #268

Read repair stale replicas

CodingDistributed systemsMid–Senior~25 min

During a read, the coordinator gathers each replica's view of a key as [replica_id, version, value], where higher integer `version` is fresher and ties are broken by the lexicographically larger `value` (a deterministic last-write-wins conflict resolver). The winning (version, value) is the freshest under this rule. Return a list of replica_ids (sorted ascending as strings) that are STALE — i.e., whose (version, value) is not equal to the winning pair — because the coordinator must send them the repaired value. If all replicas already agree, return an empty list.

Implement
read_repair_targets(replica_views: list[list]) → list[str]
Examples
in[[["r1",5,"blue"],["r2",5,"blue"],["r3",4,"red"]]]out["r3"]
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 25 min
InputExpectedGot
[[["r1",5,"blue"],["r2",5,"blue"],["r3",4,"red"]]]["r3"]not run yetsample