Problem Statement
Several individuals numbered 0, 1, 2... N-1 are competing in a tournament. Several rounds are played, and a certain number of points are scored each round. The individual with the highest total score sum from all rounds, is the overall winner.
You are given
Return the index of the player with the highest total score. If there is a tie, return the lowest index of those players that were tied.
Definition
- Class:
- OverallScores
- Method:
- findWinner
- Parameters:
- int, int[]
- Returns:
- int
- Method signature:
- int findWinner(int N, int[] scores)
- (be sure your method is public)
Constraints
- N will be between 2 and 10, inclusive.
- The number of elements in scores will be divisible by N.
- scores will contain between 2 and 50 elements, inclusive.
- Each element of scores will be between 0 and 100, inclusive.
Examples
2
{ 10, 20, 30, 40 }
Returns: 1
Player 0 scored 10+30 = 40, while player 1 scored 20+40 = 60.
2
{ 1, 1, 1, 1 }
Returns: 0
It's a tie with 2 points each, so we choose the lower index.
3
{ 71, 23, 18, 15, 28, 93, 11, 12, 13 }
Returns: 2
Player 2 had one very big score for the middle round.
2
{ 11, 2, 3, 4, 5, 6 }
Returns: 0
3
{ 1, 2, 3, 4, 5, 6 }
Returns: 2
2
{20, 10, 20, 10 }
Returns: 0
2
{1, 1, 1, 2 }
Returns: 1
2
{1, 2, 1, 2 }
Returns: 1
2
{1, 1, 2, 1, 1, 10 }
Returns: 1
3
{71, 23, 18, 15, 28, 93, 11, 12, 13 }
Returns: 2
2
{10, 20, 30, 40 }
Returns: 1
2
{40, 30, 20, 10 }
Returns: 0
2
{0, 0, 0, 0, 0, 1 }
Returns: 1
2
{0, 0, 0, 0 }
Returns: 0