3471. Minimum Average of Smallest and Largest Elements
My accepted C++ solution to LeetCode problem 3471, Minimum Average of Smallest and Largest Elements, running in 0ms.
- Difficulty: Easy
- C++
- Runtime 0ms
- Memory 25.7MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
C++
Accepted on LeetCode — runtime 0ms, memory 25.7MB, accepted 2025-12-27.
class Solution {
public:
double minimumAverage(vector<int>& nums) {
sort(nums.begin(), nums.end());
double minAvg = INT_MAX;
int n = nums.size();
for (int i = 0; i < n / 2; i++)
minAvg = min(minAvg, (nums[i] + nums[n - 1 - i]) / 2.0);
return minAvg;
}
};