Code Room
CodingMediumcod-g1091
Subject Vector clocks for replica causalityLevel Mid–Senior~20 minCommon in Distributed systems interviewsIndustries Technology

Question

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]) → str
Examples
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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.