Mean, Median, and Mode Problem Statement

Given an integer array ARR of size N, you need to compute the following three statistical measures:

  1. Mean: Implement the function mean() to calculate the mean of the array.
  2. Median: Implement the function median() to calculate the median of the array.
  3. 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 the ith element of the array.
  • Time limit: 1 sec
Note:
  • Mean and Median should be returned in the form P/Q, where P and Q are coprime integers, and Q ≠ 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...
Mobikwik Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter