Mean, Median, and Mode Problem Statement
Given an integer array ARR
of size N
, you need to compute the following three statistical measures:
- Mean: Implement the function
mean()
to calculate the mean of the array. - Median: Implement the function
median()
to calculate the median of the array. - Mode: Implement the function
mode()
to determine the mode of the array.
Return these measures in the specified format.
Example:
Input:
ARR = {1, 1, 2, 2, 3, 3, 4}
Output:
Mean: P Q
Median: P Q
Mode: 1
Explanation:
For the given array, the mode will be 1, as it is the smallest of all the possible modes (1, 2, and 3).
Constraints:
1 <= T <= 5
1 <= N <= 105
1 <= ARR[i] <= 106
- Where
ARR[i]
denotes theith
element of the array. - Time limit: 1 sec
Note:
- Mean and Median should be returned in the form
P/Q
, whereP
andQ
are coprime integers, andQ ≠ 0
. - If multiple elements have the same highest frequency, return the smallest one as the mode.
Be the first one to answer
Add answer anonymously...
Top Mobikwik Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app