Skip to main content
Back to problems
#1491
Easy Algorithms

Average salary excluding the minimum and maximum salary

Array Sorting
63.5% acceptance
Feb 25, 2026
2275
187
You are given an array of unique integers salary where salary[i] is the salary of the ith employee. Return the average salary of employees excluding the minimum and maximum salary. Answers within 10^-5 of the actual answer will be accepted.

Solution

Rust
Time O(n)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn average(salary: Vec<i32>) -> f64 {
    let min = *salary.iter().min().unwrap();
    let max = *salary.iter().max().unwrap();
    let sum: i32 = salary.iter().sum::<i32>() - min - max;
    sum as f64 / (salary.len() - 2) as f64
  }
}