Problem · Array

Find Mean and Mode

Learn this problem
EasyCiscoINTERNOA
See Cisco hiring insights

Problem statement

The arithmetic mean of N numbers is the sum of all the numbers, divided by N. The mode of N numbers is the most frequently occurring number.

Write an algorithm to find the mean and mode of a set of given numbers.

Input

The first line of input consists of an integer- inputNum, representing the number of elements in the set (N). The next line consists of N space-separated integers representing the elements of the given set.

Output

Print K space-separated integers where the first number is the mean of the input numbers and the second number is the mode (where K=2).

Note: If mean calculated is in decimal, print its floor value (Floor is the greatest integer less than or equal to that integer; floor[2.4] = 2).

Function

findMeanAndMode(nums: int[]) → int[]

Examples

Example 1

nums = [1, 2, 7, 3, 2]return = [3, 2]

The mean of the numbers 1, 2, 7, 3, 2 is (1+2+7+3+2)/5 = 15/5 = 3.

The number 2 occurs most frequently, hence it is the mode.

Therefore, the output is 3 2.

More Cisco problems

drafts saved locally
public int[] findMeanAndMode(int[] nums) {
  // write your code here
}
nums[1, 2, 7, 3, 2]
expected[3, 2]
checking account