Best Easy Approach 😍🔥✅ Detailed Explanation
Approach\n1. Sort the Array: Sort the input array to arrange the elements in ascending order.\n2. Initialize the Minimum Average: Compute the average of the fir
# Approach\n1. **Sort the Array:** Sort the input array to arrange the elements in ascending order.\n2. **Initialize the Minimum Average:** Compute the average of the first and last elements of the sorted array. This serves as the initial minimum average.\n3. **Iterate and Compare:** Loop through the first half of the sorted array, compute the average of each pair of elements from the beginning and the end of the array, and update the minimum average if the current average is smaller.\n4. **Return the Minimum Average:** After completing the iteration, return the smallest average encountered.\n\n\n# Complexity\n- Time complexity: O(nlogn), The overall time complexity is dominated by the sorting step, so it is O(nlogn).\n\n- Space complexity: O(1)\n\n# Code\n```Java []\nclass Solution {\n    public double minimumAverage(int[] nums) {\n        int n = nums.length;\n        Arrays.sort(nums);\n        double minAvg = (nums[0] + nums[n - 1]) / 2.0;\n\n        for (int i = 1; i < n / 2; i++) {\n            double avg = (nums[i] + nums[n - 1 - i]) / 2.0;\n            if (avg < minAvg) {\n                minAvg = avg;\n            }\n        }\n\n        return minAvg;\n    }\n}\n```\n```C++ []\nclass Solution {\npublic:\n    double minimumAverage(std::vector<int>& nums) {\n        int n = nums.size();\n        std::sort(nums.begin(), nums.end());\n        double minAvg = (nums[0] + nums[n - 1]) / 2.0;\n\n        for (int i = 1; i < n / 2; ++i) {\n            double avg = (nums[i] + nums[n - 1 - i]) / 2.0;\n            if (avg < minAvg) {\n                minAvg = avg;\n            }\n        }\n\n        return minAvg;\n    }\n};\n\n```\n```Python []\nfrom typing import List\n\nclass Solution:\n    def minimumAverage(self, nums: List[int]) -> float:\n        n = len(nums)\n        nums.sort()\n        min_avg = (nums[0] + nums[-1]) / 2\n\n        for i in range(1, n // 2):\n            avg = (nums[i] + nums[n - 1 - i]) / 2\n            if avg < min_avg:\n                min_avg = avg\n\n        return min_avg\n```\n```Javascript []\n/**\n * @param {number[]} nums\n * @return {number}\n */\nvar minimumAverage = function(nums) {\n    const n = nums.length;\n    nums.sort((a, b) => a - b);\n    let minAvg = (nums[0] + nums[n - 1]) / 2;\n\n    for (let i = 1; i < n / 2; i++) {\n        const avg = (nums[i] + nums[n - 1 - i]) / 2;\n        if (avg < minAvg) {\n            minAvg = avg;\n        }\n    }\n\n    return minAvg;\n};\n```\n```Golang []\nfunc minimumAverage(nums []int) float64 {\n    n := len(nums)\n    sort.Ints(nums)\n    minAvg := float64(nums[0] + nums[n-1]) / 2.0\n\n    for i := 1; i < n/2; i++ {\n        avg := float64(nums[i] + nums[n-1-i]) / 2.0\n        if avg < minAvg {\n            minAvg = avg\n        }\n    }\n\n    return minAvg\n}\n```\n```C []\n#include <stdlib.h>\n\nint compare(const void *a, const void *b) {\n    return (*(int*)a - *(int*)b);\n}\n\ndouble minimumAverage(int* nums, int numsSize) {\n    int n = numsSize;\n    qsort(nums, n, sizeof(int), compare);\n    double minAvg = (nums[0] + nums[n - 1]) / 2.0;\n\n    for (int i = 1; i < n / 2; i++) {\n        double avg = (nums[i] + nums[n - 1 - i]) / 2.0;\n        if (avg < minAvg) {\n            minAvg = avg;\n        }\n    }\n\n    return minAvg;\n}\n```\n```Dart []\nclass Solution {\n  double minimumAverage(List<int> nums) {\n    nums.sort();\n    int n = nums.length;\n    double minAvg = (nums[0] + nums[n - 1]) / 2.0;\n\n    for (int i = 1; i < n / 2; i++) {\n      double avg = (nums[i] + nums[n - 1 - i]) / 2.0;\n      if (avg < minAvg) {\n        minAvg = avg;\n      }\n    }\n\n    return minAvg;\n  }\n}\n```
['Array', 'C', 'Sorting', 'Python', 'C++', 'Java', 'Go', 'Python3', 'JavaScript']