16. President

Difficulty: 

Members of a club have participated in a poll to elect the next president. We know the winner has the majority of the votes (strictly more votes than other candidates combined). Given an array of the votes, determine who the next president is. Try to solve this problem in linear time.

Input:

president([
  3,
  2,
  1,
  3,
  2,
  2,
  1,
  2,
  2
]);

Output:

2

Time Limit:

500 (ms)

Hints (hover to see):

  • Hint #1
  • Hint #2



Results

ProblemsAcceptedWrongTimed OutError
120000

Input:

Expected Output:

Output: