Counting sort + 2 pointers||0ms beats100%
Intuition\n Describe your first thoughts on how to solve this problem. \nEasy question is solved with O(n+m) time.\nCounting soert then use 2 pointers\n# Approa
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nEasy question is solved with O(n+m) time.\nCounting soert then use 2 pointers\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Count `freq` for each x in `nums`; just 1st part of counting sort\n2. Use 2 pointers i<j to move:\n    - while freq[i]==0, i++\n    - while freq[j]==0, j--\n    - if i>j break the loop\n    - update minAv as min(minAv, (i+j)/2.0)\n    - if --freq[i]==0 i++\n    - if --freq[j]==0 j--\n3. minAv is the answer\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n $$O(n+m)$$ where $m=\\max(nums)$\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n $$O(m)$$\n# Code\n```\nclass Solution {\npublic:\n    static double minimumAverage(vector<int>& nums) {\n        int n=nums.size();\n        char freq[51]={0}, xMin=50, xMax=1;\n        double sum=0;\n        for(char x: nums){\n            freq[x]++;\n            xMin=min(xMin, x);\n            xMax=max(xMax, x);\n        }\n        double minAv=50;\n        for(char i=xMin, j=xMax; n>0; n-=2){\n            while (i<j && freq[i]==0) i++;\n            while (i<j && freq[j]==0) j--;\n            if (i > j) break;\n            minAv=min({minAv, double(i+j)/2 });\n            if (--freq[i]==0) i++;\n            if (--freq[j]==0) j--;\n        }\n        return minAv;\n    }\n};\n\n\n\n\nauto init = []() {\n    ios::sync_with_stdio(0);\n    cin.tie(0);\n    cout.tie(0);\n    return \'c\';\n}();\n```
['Two Pointers', 'Counting Sort', 'C++']