Connection Status:
Competition Arena > ClassScores
SRM 258 · 2005-08-10 · by erinn · Simple Math, Simple Search, Iteration
Class Name: ClassScores
Return Type: int[]
Method Name: findMode
Arg Types: (vector<int>)
Problem Statement

Problem Statement

A teacher has just finished grading the test papers for his class. To get an idea of how difficult the test was, he would now like to determine the most common score on the test. In statistics, this is called the "mode" of a set of data points. For instance, if the scores were {65, 70, 88, 70}, then the mode would be 70, since it appears twice while all others appear once.

Sometimes, in the case of a tie, the mode will be more than one number. For instance, if the scores were {88, 70, 65, 70, 88}, then the mode would be {70, 88}, since they both appear most frequently.

You are given a int[] scores. You are to return a int[] representing the mode of the set of scores. In the case of more than one number, they should be returned in increasing order.

Constraints

  • scores will contain between 1 and 50 elements, inclusive.
  • Each element of scores will be between 0 and 100, inclusive.
Examples
0)
{65, 70, 88, 70}
Returns: {70 }

The first example from the problem statement.

1)
{88, 70, 65, 70, 88}
Returns: {70, 88 }

The second example from the problem statement.

2)
{92, 56, 14, 73, 22, 38, 93, 45, 55}
Returns: {14, 22, 38, 45, 55, 56, 73, 92, 93 }

With no duplicates, all of the elements are the most frequent (appearing once each).

3)
{0}
Returns: {0 }
4)
{99, 99, 99, 99, 74, 74, 74, 74, 32, 32, 32, 32, 5, 6, 7}
Returns: {32, 74, 99 }

Submissions are judged against all 43 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class ClassScores with a public method vector<int> findMode(vector<int> scores) · 43 test cases · 2 s / 256 MB per case

Submitting as anonymous