TopcoderArchiveVisit Topcoder
Archive
Algorithm problem

Olympics

Problem statement, definition, constraints, and public examples.

Problem Statement

In the Olympics, there are several subjective events in which judges give out scores to the competitors based on their performances. However, because some judges are biased, they toss out the high and low judges' scores before summing the scores to get the final score.

Write the class Olympics which contains the method getScore. This will take an int[] scores representing the scores given by the judges. Your method should return the sum of the scores which will count toward the final score.

Definition

Class:
Olympics
Method:
getScore
Parameters:
int[]
Returns:
int
Method signature:
int getScore(int[] scores)
(be sure your method is public)

Notes

  • There is exactly one high score and one low score thrown out. For example, if the scores were {4,4,10,10}, you would throw out one 4 and one 10, for a total of 14.

Constraints

  • scores will contain between 3 and 20 elements, inclusive.
  • each element of scores will be between 0 and 10, inclusive.

Examples

  1. {3,2,4,5,9,8,6}
    Returns: 26
    You drop a 9 and a 2, then add together 3,4,5,8, and 6 to get 26.
  2. {1,1,1,1,10,10,10,10}
    Returns: 33
    Remember, only one high score and one low score is dropped. Therefore, we drop a 10 and a 1, and add 1, 1, 1, 10, 10, and 10 to get 33.
  3. {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10}
    Returns: 0
  4. {1,4,1,9,3,3,9,7,9,3,8,4,9,5,8,9,1,1,3,2}
    Returns: 89
Back to all problems