A hybrid logical clock combines a wall-clock component with a logical counter. The pair preserves causality even when the local physical clock stalls or moves backward.
Design a HybridLogicalClock class:
HybridLogicalClock() starts at timestamp [0, 0].int[] local(int physicalTime) records a local event and returns the updated timestamp.int[] receive(int physicalTime, int remoteWall, int remoteLogical) records receipt of a remote timestamp and returns the updated timestamp.For a local event:
physicalTime is greater than the stored wall component, set the wall component to physicalTime and reset the logical component to 0.For a received event, let nextWall be the maximum of physicalTime, the stored wall component, and remoteWall. Compute the new logical component as follows:
remoteWall equal nextWall, use max(storedLogical, remoteLogical) + 1.nextWall, use storedLogical + 1.remoteWall equals nextWall, use remoteLogical + 1.0.Store and return [nextWall, nextLogical].
Input:
Output:
Explanation: The first event follows physical time. The second event uses the logical counter because physical time is unchanged. The received timestamp then advances beyond logical values 1 and 4.
Input:
Output:
Explanation: Physical time 50 is strictly greater than both wall components, so the logical component resets to 0.
0 <= physicalTime, remoteWall <= 10^90 <= remoteLogical <= 10^910^5 method calls are made per clock.| Call | Returns |
|---|---|
| new HybridLogicalClock() | null |
| local(100) | [100,0] |
| local(100) | [100,1] |
| receive(100, 100, 4) | [100,5] |
The first event follows physical time, the second breaks a tie logically, and the received timestamp advances beyond both logical components.
Run checks these cases. Submit also runs a larger hidden set.

