Average Salary Excluding the Minimum and Maximum Salary
Here’s a simple step-by-step guide to solving this problem:
- First, find the maximum and minimum values in the salary array.
- Next, sum up all the values in the salary array and subtract the maximum and minimum values from this sum.
- Finally, divide this sum by the number of employees minus 2 (to account for the removed max and min salaries).
This will give the average salary of the employees excluding the maximum and minimum salary.
Python solution:
|
|
This solution works in linear time complexity, i.e., O(n), where n is the number of employees. It meets the constraints 3 <= salary.length <= 100, 1000 <= salary[i] <= 106, and all salary values are unique.