Vector clock causality comparison

Write codeMedium20 minAmazon style

Your task

Two replicas each tag a write with a vector clock: a map from node id to a non-negative integer counter. Given two vector clocks a and b (as dicts; a missing node means 0), determine their causal relationship. Return 'before' if a happens-before b (a <= b componentwise and a != b), 'after' if b happens-before a, 'equal' if they are identical, and 'concurrent' otherwise. This is the comparison a Dynamo-style store uses to decide whether one version dominates another or whether the two versions conflict.

Examples

vc_compare(a: dict[str,int], b: dict[str,int]) -> str
Example 1
Inputvc_compare({"n1": 1, "n2": 0}, {"n1": 2, "n2": 0})
Output"before"