Code RoomSloppy quorum with hinted handoff
MediumPrep Room Coding #270

Sloppy quorum with hinted handoff

CodingDistributed systemsMid–Senior~28 min

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

Implement
sloppy_quorum_targets(pref_list: list[str], alive: list[str], fallback: list[str], w: int) → list[str]
Examples
in[["A","B","C"],["A","B","C"],["D","E"],2]out["A","B"]
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 28 min
InputExpectedGot
[["A","B","C"],["A","B","C"],["D","E"],2]["A","B"]not run yetsample