Code RoomQuorum read consistency decision
MediumPrep Room Coding #260

Quorum read consistency decision

CodingDatabases & SQLMid–Senior~25 min

A Dynamo-style store uses N replicas with read quorum R and write quorum W. A read collects responses from some replicas, each a pair [version, value] where higher integer `version` is fresher. The read succeeds only if at least R replicas responded. Given N, R, W, and the list of responses, return a 3-element list [ok, value, repair_count]: `ok` is True iff strong consistency is guaranteed for this read (R + W > N) AND at least R replicas responded; `value` is the value attached to the highest version among responders (empty string if no responses); `repair_count` is the number of responding replicas whose version is strictly less than the max version (these are stale and need read-repair).

Implement
quorum_read(n: int, r: int, w: int, responses: list[list]) → list
Examples
in[3,2,2,[[5,"x"],[5,"x"],[4,"old"]]]out[true,"x",1]
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
[3,2,2,[[5,"x"],[5,"x"],[4,"old"]]][true,"x",1]not run yetsample