You have an array of floating point numbers averages which is initially empty. You are given an array nums of n integers where n is even.
You repeat the following procedure n / 2 times:
Remove the smallest element, minElement, and the largest element maxElement, from nums.
Add (minElement + maxElement) / 2 to averages.
Return the minimum element in averages.
class Solution {
public:
double minimumAverage(vector<int>& v) {
int n=v.size();
sort(v.begin(),v.end());
int i=0,j=n-1;
double ans=1000;
while(i<j)
{
double k=(v[i]+v[j])/(2*1.0);
ans=min(ans,k);
i++;
j--;
}
return ans;
}
};