LeetCode solutions

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

Read the problem on LeetCode View on GitHub

C++

Accepted on LeetCode — runtime 0ms, memory 25.7MB, accepted 2025-12-27.

cpp
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;
    }
};

Source