Trains the technique from
LeetCode 169Majority ElementThis 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.
Example 1
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
Three entries out of five hold -6. Drift can run either side of the reference, so a negative figure is a perfectly ordinary answer.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def quorum_drift(reports: list[int]) -> int:public int quorumDrift(int[] reports)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.