All problems
0120EasyArrayHash TableDivide and ConquerSortingCountingBoyer–Moore Majority Vote Algorithm

Quorum Drift Value

Tracked in this browser only
Write code

Trains the technique from

LeetCode 169Majority Element

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A monitoring service asks every node in a cluster for the same figure: how far that node's clock has drifted from the reference, in signed milliseconds. Nodes with a broken sensor answer with whatever number their hardware happens to produce, so the array reports mixes trustworthy answers with junk, in no particular order.

The cluster is provisioned so that the healthy nodes are always a strict majority: one value occupies more than half of the entries of reports. Return that value.

The array is streamed in from the wire, so solve it with a single left-to-right pass over reports and only a constant amount of bookkeeping. Do not sort and do not tally every distinct value.

Examples

Example 1

Input
reports = [4, 7, 4]
Output
4

Two of the three nodes answered 4, which is more than half, so 7 is the faulty reading. Note that the answer is not the entry sitting in the middle.

Example 2

Input
reports = [-6, -6, 2, -6, 9]
Output
-6

Three entries out of five hold -6. Drift can run either side of the reference, so a negative figure is a perfectly ordinary answer.

Constraints

  • n == reports.length
  • 1 <= n <= 5 * 10^4
  • -10^9 <= reports[i] <= 10^9
  • The input is provisioned so that some value appears more than n / 2 times

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def quorum_drift(reports: list[int]) -> int:
Java
public int quorumDrift(int[] reports)
September 7
Apply