47. Average Salary Excluding Min and Max

EasyArrayArray

You are given an array salary where salary[i] is the salary of the i-th employee. Return the average salary of employees excluding the minimum and maximum salary, rounded to 5 decimal places.

Input: An integer array salary of length n.

Output: A float — average salary excluding min and max.

Examples

Example 1
Input: [4000,3000,1000,2000]
Output: 2500.00000
Explanation: Remove min(1000) and max(4000). Average of [3000,2000] = 2500.
Example 2
Input: [1000,2000,3000]
Output: 2000.00000
Explanation: Remove 1000 and 3000. Average of [2000] = 2000.
Example 3
Input: [6000,5000,4000,3000,2000,1000]
Output: 3500.00000
Explanation: Remove 1000,6000. Average of [5000,4000,3000,2000] = 3500.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →