Sloppy quorum with hinted handoff

Write codeMedium28 minAmazon style

Your task

A Dynamo-style write needs W acknowledgements. The preference list pref_list is the ordered list of node ids that should hold this key (length >= W). Some nodes are down: alive is the set (given as a list) of node ids currently reachable. Under sloppy quorum, the coordinator walks the preference list in order, sending to each alive node until it has W acks; if it cannot get W acks from the preference list alone, it falls back to fallback nodes (an ordered list, walked in order) which accept hinted handoff. Return the ordered list of node ids that ultimately receive the write (those chosen, in selection order). If even using all alive preference + fallback nodes you cannot reach W, return the ids gathered so far (a partial, failed write).

Examples

sloppy_quorum_targets(pref_list: list[str], alive: list[str], fallback: list[str], w: int) -> list[str]
Example 1
Inputsloppy_quorum_targets(["A", "B", "C"], ["A", "B", "C"], ["D", "E"], 2)
Output["A", "B"]