When a process receives a message, its vector clock must absorb every event known to the sender and then record the receive as a new local event.
Design a VectorClockReceiver class:
VectorClockReceiver() creates a stateless updater.int[] update(int[] local, int[] received, int index) returns the receiver's new clock.
The two clocks have the same length. Build the result in two steps:
- Set each component to
max(local[i], received[i]). - Increment the component at
index by 1.
Do not modify either input clock.
Example 1:
Input:
Output:
Explanation: Merging produces [1,1,0]. The receiver is process 0, so its component becomes 2.
Example 2:
Input:
Output:
Explanation: The component-wise maximum is [2,3,1]. Incrementing component 2 records the receive event.
Constraints
1 <= local.length == received.length <= 10^50 <= local[i], received[i] <= 10^90 <= index < local.length- The incremented component fits in a signed 32-bit integer.
- At most
100 calls are made to update.