Maintaining mnSum for min & max elements || Short || C++
Intuition\nAs per problem we need to find the min avg for max & min element present in vector, so average to be minimum we need to find the minimum sum of max &
# Intuition\nAs per problem we need to find the min avg for max & min element present in vector, so average to be minimum we need to find the minimum sum of max & min element.\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nSo, to find that we sorted the array so that for each cycle/iteration, for each min element index i we can get n - i - 1 max element index.\nSo, by keeping a variable mnSum & iterating on array we can get mnSum.\nAt last we can return avg by dividing it by 2.\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(nlogn) \nAs we are sorting vector which takes O(nlogn) time.\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\nWe are not using any extra space.\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\nHope it helps, we can further decrease time complexity by using Counting sort but in that case extra space will be used.\n\n# Code\n```\nclass Solution {\npublic:\n    double minimumAverage(vector<int>& nums) {\n        int n = nums.size();\n\n        // sorting the array/vector to get max & min element for each iteration easily\n        sort(nums.begin(), nums.end());\n\n        // variable to store min sum of min & max element \n        int mnSum = INT_MAX;\n        for(int i = 0 ; i < n / 2 ; i++) {\n            mnSum = min(mnSum, nums[i] + nums[n - i - 1]);\n        }\n\n\n        // returning avg.\n        return mnSum / 2.0;\n    }\n};\n```
['Sorting', 'C++']