Average Salary Excluding the Minimum and Maximum Salary - Problem
You're working as a payroll analyst for a company and need to calculate the fair average salary for performance evaluation purposes.
Given an array of unique integers salary where salary[i] represents the salary of the i-th employee, you need to:
- ๐ซ Exclude the minimum salary (outlier - might be intern/part-time)
- ๐ซ Exclude the maximum salary (outlier - might be executive/exceptional case)
- ๐ Calculate the average of the remaining salaries
This approach helps eliminate extreme outliers that might skew the average compensation analysis.
Return: The average salary after removing the minimum and maximum values.
Note: Answers within 10-5 of the actual answer will be accepted.
Input & Output
example_1.py โ Basic Case
$
Input:
salary = [4000,3000,1000,2000]
โบ
Output:
2500.0
๐ก Note:
Minimum salary is 1000, maximum salary is 4000. After excluding them, we have [3000, 2000]. Average = (3000 + 2000) / 2 = 2500.0
example_2.py โ Higher Salaries
$
Input:
salary = [1000,2000,3000]
โบ
Output:
2000.0
๐ก Note:
Minimum is 1000, maximum is 3000. After exclusion: [2000]. Average = 2000 / 1 = 2000.0
example_3.py โ Larger Dataset
$
Input:
salary = [6000,5000,4000,3000,2000,1000]
โบ
Output:
3500.0
๐ก Note:
Min=1000, Max=6000. Remaining: [5000,4000,3000,2000]. Average = (5000+4000+3000+2000) / 4 = 3500.0
Constraints
- 3 โค salary.length โค 100
- 1000 โค salary[i] โค 106
- All the integers of salary are unique
- Answers within 10-5 of the actual answer will be accepted
Visualization
Tap to expand
Understanding the Visualization
1
Data Collection
Gather all employee salary data into an array
2
Outlier Detection
Identify minimum and maximum salaries as outliers
3
Fair Average
Calculate average excluding the extreme values
Key Takeaway
๐ฏ Key Insight: By eliminating salary outliers (minimum and maximum), we get a more representative average that better reflects typical employee compensation levels.
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code