PN-counter CRDT replica merge

Write codeMedium25 minFigma and Amazon style

Your task

A PN-counter is a CRDT supporting increments and decrements that converges across replicas without coordination. Each replica keeps two grow-only maps per node: P (total increments per node) and N (total decrements per node). To merge a set of replica states you take, for every node, the maximum P and maximum N seen across all replicas; the counter's value is sum(P) - sum(N). Each replica state is given as [P_dict, N_dict]. Given a list of replica states, return the converged integer value after merging them all.

Examples

pn_counter_value(replicas: list[list]) -> int
Example 1
Inputpn_counter_value([[{"a": 5, "b": 2}, {"a": 1}], [{"a": 3, "b": 4}, {"a": 1, "c": 2}]])
Output6