A grow-only counter, or G-Counter, stores one nondecreasing component per replica. Its value is the sum of those components. Two replicas converge by retaining the greatest count observed for each component.
Design a GCounterMerger class:
GCounterMerger() creates a stateless merger.int mergedValue(int[] a, int[] b) returns the value after merging the two states.
The arrays have the same length. Merge component i as max(a[i], b[i]), then return the sum of all merged components. Do not mutate either input array.
Example 1:
Input:
Output:
Explanation: The merged state is [3,2,3], so its value is 3 + 2 + 3 = 8.
Example 2:
Input:
Output:
Explanation: The two states contain progress from different replicas. The merged state is [10,10,0].
Constraints
1 <= a.length == b.length <= 10^40 <= a[i], b[i] <= 10^4- The merged value fits in a signed 32-bit integer.
- At most
100 calls are made to mergedValue.