Vector clock causality comparison
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.
Implement
vc_compare(a: dict[str,int], b: dict[str,int]) → strExamples
in
[{"n1":1,"n2":0},{"n1":2,"n2":0}]out"before"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 20 min
solution.py
InputExpectedGot
[{"n1":1,"n2":0},{"n1":2,"n2":0}]"before"not run yetsample