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
Definition
- Class:
- ClassScores
- Method:
- findMode
- Parameters:
- int[]
- Returns:
- int[]
- Method signature:
- int[] findMode(int[] scores)
- (be sure your method is public)
Constraints
- scores will contain between 1 and 50 elements, inclusive.
- Each element of scores will be between 0 and 100, inclusive.
Examples
{65, 70, 88, 70}
Returns: {70 }
The first example from the problem statement.
{88, 70, 65, 70, 88}
Returns: {70, 88 }
The second example from the problem statement.
{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).
{0}
Returns: {0 }
{99, 99, 99, 99, 74, 74, 74, 74, 32, 32, 32, 32, 5, 6, 7}
Returns: {32, 74, 99 }
{5,45,4,92,32,26,40,79,18,51,40,78,41,40,26,84,54,38,45,12,33,23,44,81,67,39,72,93,67,53,9,67,11,39,15,79,7,85,9,31,77,25,67,48}
Returns: {67 }
{77,52,99,32,33,65,39,6,52,17,85,83,4,39,5,85,27,1,45,13,28,68,66,9,87,74,22,44,98,25,52,34,17,24,100,77,56,27,60,20,81,12,48,46,50,88,99,89,69,16}
Returns: {52 }
{80,77,66,43,68,48,88,93,99,33,15,81,41,10,96,27,66,72,36,65,4,27,83,11,36,43,21,62,6,94,7,11,60,50,12,0}
Returns: {11, 27, 36, 43, 66 }
{8,2,84,19,100,43,26,26,96,20,23,77,45,95,47,86,5,81,14,31,48,43,86,67,17,27,81,62,15,9,29,62,8,73,34,82,60,10,77,18,87,49}
Returns: {8, 26, 43, 62, 77, 81, 86 }
{27,43,6,95,93,32,61,99,7,31,56,61,97,55,29,29,52,38,61,19,55,40,51,87,67,82,19,25,44,100,37,80,78,31,74,100,53,22,75,4,44,58,63,79}
Returns: {61 }
{25,67,97,10,83,71,62,15,93,90,81,51}
Returns: {10, 15, 25, 51, 62, 67, 71, 81, 83, 90, 93, 97 }
{29,60,32,50,38,22,23,74,0,53,96,91,77,72,20,94,68,30,81,35,93,24,14,15,40,47,72,82,43,58,12,70,80,74,11,55,2,95}
Returns: {72, 74 }
{4,90,44,48,55,19,43,12,3,73,4,91,9,61,51,41,1,75,66,53}
Returns: {4 }
{23,58,30,67,36,56,9,27,86,37,98,89,44,64,39,28,56,57,100,55,82,93,83,61,22,20,71,7,75,9,86,34}
Returns: {9, 56, 86 }
{4,82,88,47,99,53,86,40,92,83,92}
Returns: {92 }
{67,97}
Returns: {67, 97 }
{28,55,60,12,97,86,87,3,32,71,81,99,46,68,100,28,18,89,45,98}
Returns: {28 }
{17,73,43,18,99,36,11,62,53,48,71,23,78,71,41,22,74,28,55,43,43,48,39,90,32,21,21,60,1,99,62,49,22,95,17,75,98,37,15,30,3,23,70,60,65}
Returns: {43 }
{11,61,48,38}
Returns: {11, 38, 48, 61 }
{30,79,52,98}
Returns: {30, 52, 79, 98 }
{9,81,29,81,100,20,47,45,86,48,22,62,29,63,68,78,45,48,41,3,59,59,77,15,99,42,45,80,17,70,37,9,38,3,69,35,24,89,17,8,72,61,75,32,35,93}
Returns: {45 }
{36,70,52}
Returns: {36, 52, 70 }
{1,100,93,14}
Returns: {1, 14, 93, 100 }
{89,71,14,12,0,81,23,92,63}
Returns: {0, 12, 14, 23, 63, 71, 81, 89, 92 }
{20,75,15,82,38,43,70,62,90,39,56,4,84,17,66,63,66,21,26,90,86,85,93,50,54,58,69,62}
Returns: {62, 66, 90 }
{92, 56, 14, 73, 22, 38, 93, 45, 55 }
Returns: {14, 22, 38, 45, 55, 56, 73, 92, 93 }
{88, 70, 65, 70, 88 }
Returns: {70, 88 }
{100, 100, 100, 50, 100, 88, 100 }
Returns: {100 }
{1, 10, 1, 100, 1, 99 }
Returns: {1 }
{10, 10, 10, 10, 10, 13, 16, 17, 20, 20, 20, 20, 20, 30, 30, 30, 30, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 }
Returns: {100 }
{65, 65, 88, 88, 65 }
Returns: {65 }
{65, 70, 88, 70, 100, 100, 100 }
Returns: {100 }
{65, 65, 88, 88 }
Returns: {65, 88 }
{92, 56, 14, 73, 22, 38, 93, 45, 55, 100 }
Returns: {14, 22, 38, 45, 55, 56, 73, 92, 93, 100 }
{92, 56, 14, 100, 22, 38, 93, 45, 55 }
Returns: {14, 22, 38, 45, 55, 56, 92, 93, 100 }
{0, 0, 0, 0, 1, 1 }
Returns: {0 }
{100, 0, 100, 100 }
Returns: {100 }
{1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3 }
Returns: {3 }
{92, 14, 14, 92, 38, 38, 93, 93, 55 }
Returns: {14, 38, 92, 93 }
{92, 56, 14, 73, 22, 38, 93, 45, 55, 55, 45, 45 }
Returns: {45 }
{100, 100, 0 }
Returns: {100 }
{100, 25, 25, 25, 30, 34, 34, 30, 34, 100 }
Returns: {25, 34 }
{2, 1, 2 }
Returns: {2 }