Quorum read consistency decision

Write codeMedium25 minAmazon style

Your task

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).

Examples

quorum_read(n: int, r: int, w: int, responses: list[list]) -> list
Example 1
Inputquorum_read(3, 2, 2, [[5, "x"], [5, "x"], [4, "old"]])
Output[True, "x", 1]