Mean of Array After Removing Some Elements LeetCode solution in C++
1class Solution {2public:3double trimMean(vector<int> &arr) {4auto first = arr.begin() + arr.size() / 20;5auto second = arr.end() - arr.size() / 20;6nth_element(arr.begin(), first, arr.end());7nth_element(first, second, arr.end());8return accumulate(first, second, 0.0) / distance(first, second);9}10};