Quorum write safety

Write codeEasy14 minAmazon style

Your task

A control plane replicates every feature flag write to replica_count storage replicas, and it is configured with a write quorum and a read quorum. A write counts as safely committed only when three things hold. Each quorum is no larger than replica_count, so it can actually be assembled. write_quorum plus read_quorum is greater than replica_count, so any later read is forced to touch at least one replica that took the write. And at least write_quorum replicas acknowledged that particular entry. Entry i of the log wrote flag_names[i] and collected ack_counts[i] acknowledgements. Return the flag names of the entries that are not safely committed, in log order. A flag written twice is reported once per failing entry. Return an empty list when every entry is safe.

Examples

writes_missing_quorum(replica_count: int, write_quorum: int, read_quorum: int, flag_names: list[str], ack_counts: list[int]) -> list[str]
Example 1
Inputwrites_missing_quorum(3, 2, 2, ["dark_mode", "new_checkout", "beta_banner"], [3, 2, 1])
Output["beta_banner"]
Example 2
Inputwrites_missing_quorum(3, 2, 1, ["search_boost", "free_trial"], [3, 2])
Output["search_boost", "free_trial"]
Example 3
Inputwrites_missing_quorum(5, 3, 3, ["retry", "retry", "retry"], [3, 2, 3])
Output["retry"]