Given voters’ ranked candidate ballots, repeatedly eliminate the candidate with the fewest current votes and transfer those votes to each ballot’s next active preference until one winner remains.
This problem is a simulation of instant-runoff voting (IRV). In each round, count only the currently active candidates, eliminate the one with the fewest votes, and transfer every affected ballot to its next preferred active candidate. Repeat until a single winner remains. A typical solution tracks candidate status and vote counts with arrays or hash maps, and advances each ballot through its ranked preferences as candidates are removed.