|
| 1 | +# 1491. Average Salary Excluding the Minimum and Maximum Salary [![share]](https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary) |
| 2 | + |
| 3 | +![easy] |
| 4 | + |
| 5 | +## Problem Statement: |
| 6 | + |
| 7 | +You are given an array of **unique** integers `salary` where` salary[i]` is the salary of the <code>i<sup>th</sup></code> employee. |
| 8 | + |
| 9 | +Return the average salary of employees excluding the minimum and maximum salary. Answers within <code>10<sup>-5</sup></code> of the actual answer will be accepted. |
| 10 | + |
| 11 | +### Example 1: |
| 12 | + |
| 13 | +``` |
| 14 | +Input: salary = [4000,3000,1000,2000] |
| 15 | +Output: 2500.00000 |
| 16 | +Explanation: Minimum salary and maximum salary are 1000 and 4000 respectively. |
| 17 | +Average salary excluding minimum and maximum salary is (2000+3000) / 2 = 2500 |
| 18 | +``` |
| 19 | + |
| 20 | +### Example 2: |
| 21 | + |
| 22 | +``` |
| 23 | +Input: salary = [1000,2000,3000] |
| 24 | +Output: 2000.00000 |
| 25 | +Explanation: Minimum salary and maximum salary are 1000 and 3000 respectively. |
| 26 | +Average salary excluding minimum and maximum salary is (2000) / 1 = 2000 |
| 27 | +``` |
| 28 | + |
| 29 | +### Constraints: |
| 30 | + |
| 31 | +- 3 <= salary.length <= 100 |
| 32 | +- 1000 <= salary[i] <= 10<sup>6</sup> |
| 33 | +- All the integers of salary are **unique**. |
| 34 | + |
| 35 | +## Solutions: |
| 36 | + |
| 37 | +### [_Java_](./AverageSalaryExcludingTheMinimumAndMaximumSalary.java) |
| 38 | + |
| 39 | +```java |
| 40 | +public double average(int[] salary) { |
| 41 | + Arrays.sort(salary); |
| 42 | + int len = salary.length; |
| 43 | + double res = 0; |
| 44 | + for (int i = 1; i < len - 1; i++) |
| 45 | + res += salary[i]; |
| 46 | + return res / (len - 2); |
| 47 | +} |
| 48 | +``` |
| 49 | + |
| 50 | +### [_..._]() |
| 51 | + |
| 52 | +``` |
| 53 | +
|
| 54 | +``` |
| 55 | + |
| 56 | +<!----------------------------------{ link }---------------------------------> |
| 57 | + |
| 58 | +[share]: https://img.icons8.com/external-anggara-blue-anggara-putra/20/000000/external-share-user-interface-basic-anggara-blue-anggara-putra-2.png |
| 59 | +[easy]: https://img.shields.io/badge/Difficulty-Easy-bright.svg |
| 60 | +[medium]: https://img.shields.io/badge/Difficulty-Medium-yellow.svg |
| 61 | +[hard]: https://img.shields.io/badge/Difficulty-Hard-red.svg |
0 commit comments