#3194
Minimum Average of Smallest and Largest Elements
easy · 85.3% accepted · 204 likes · top 96%
array · two pointers · sorting
Description
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.
Solution