FunctionRacerProblemsRace

Plurality Winner

EasyArraysPython, JavaScript, TypeScript, Java, C++

votes lists the candidate chosen on each ballot, in the order the ballots were cast. Candidates are numbered 0 to 99. The winner is the candidate with the most votes. If several candidates tie for the most votes, the winner is the one among them whose first vote came earliest in votes.

Return the winner's number. votes is never empty.

Example 1

votes [3,1,3,2,1,3]
returns 3

Candidate 3 has three votes, more than anyone else.

Example 2

votes [1,2,1,2]
returns 1

Candidates 1 and 2 have two votes each; candidate 1 was voted for first.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Arrays problems