0% found this document useful (0 votes)
2 views

Election Winner

The document outlines the rules for determining the winner of an election based on votes. The candidate with the highest number of votes wins, and in case of a tie, the winner is determined by the alphabetical order of their last names. The task is to implement the 'electionWinner' function that processes an array of votes and returns the name of the winning candidate.

Uploaded by

SUGANTHI V
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Election Winner

The document outlines the rules for determining the winner of an election based on votes. The candidate with the highest number of votes wins, and in case of a tie, the winner is determined by the alphabetical order of their last names. The task is to implement the 'electionWinner' function that processes an array of votes and returns the name of the winning candidate.

Uploaded by

SUGANTHI V
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Election Winner

The candidate with the highest number of votes wins the election;

If two or more candidates have the same number of votes , then the tied candidates’ names are ordered
alphabetically and the last name wins.

Complete the electionWinner function in your editor. It has 1 parameter; an array of strings , votes ,
describing the votes in the ballot box. This function must review these votes and representing the name
of the winning candidate.

Input Format

Locked stub code in the editor reads the following input from stdin and passes it to the function:

The first line contains an integer, n, denoting the size of the votes array.

Each line i of the n subsequent lines (where 0 <= i < n ) of strings contains a citizen’s vote in the form of
a candidate’s name.

Constraints

1 <= n <= 104

Output Format

Your function must return a string denoting the name of the winner. This is printed to stdout by the
locked stub code in your editor.

Sample Input 1

10

Alex

Michel

Harry

Dave

Michel

Victor

Harry
Alex

Mary

Mary

You might also like