AlgoMaster Logo
AlgoMasterCheck a Raft Joint-Consensus Quorummedium

Check a Raft Joint-Consensus Quorum

medium

Raft joint consensus changes cluster membership without allowing the old and new configurations to make conflicting decisions. During the transition, a vote set must contain a majority of both configurations.

Design a JointQuorumChecker class:

  • JointQuorumChecker(int[] oldMembers, int[] newMembers) stores the two voter configurations.
  • bool hasQuorum(int[] votes) returns whether the votes contain a strict majority of both configurations.

A strict majority of a configuration with n members is floor(n / 2) + 1. Count each distinct voter ID at most once, even when it appears repeatedly in votes. Ignore IDs that belong to neither configuration. A voter present in both configurations contributes to both majority counts.

Each call evaluates only its supplied votes; votes do not carry over between calls. Do not modify any input array.

Example 1:

Input:

Output:

Explanation: Voters 2 and 3 form a two-voter majority of both three-member configurations.

Example 2:

Input:

Output:

Explanation: The old configuration has votes from 1 and 2, but the new configuration has only voter 2.

Constraints

  • 1 <= oldMembers.length, newMembers.length <= 10^5
  • IDs are unique within each configuration.
  • 0 <= oldMembers[i], newMembers[i] <= 10^9
  • 0 <= votes.length <= 2 * 10^5
  • 0 <= votes[i] <= 10^9
  • At most 10^4 calls are made to hasQuorum.
Hints

Loading...
CallReturns
new JointQuorumChecker([1,2,3], [2,3,4])null
hasQuorum([2,3])true

Voters 2 and 3 form a majority of both three-member configurations.

Run checks these cases. Submit also runs a larger hidden set.