Verify a majority candidate
Return the item occurring more than half the time in a list of integers, or None when none exists.
candidate, balance = 2, 1
next_item = 1
balance += 1 if next_item == candidate else -1
print(balance)Reason about the state
Boyer-Moore cancels unequal pairs to find a candidate. A second pass is necessary because a candidate does not prove a majority. Before writing code, identify what each variable means after one iteration. Walk through the example and explain why the next transition preserves that meaning. Then check the smallest permitted input and a case with repeated values. A correct answer follows the contract for every input, including the boundary cases in the checks. Keep any input mutation within the stated rules; return a fresh result when the task asks for one.
Your task
Return the item occurring more than half the time in a list of integers, or None when none exists.
The explanation opens here once every check passes.