C++ Solution O(n) time complexity
\n# Code\n\nclass Solution {\npublic:\n    int maximizeGreatness(vector<int>& nums) {\n        unordered_map<int,int> m;\n        \n        for(int i=0;i<nums.s
\n# Code\n```\nclass Solution {\npublic:\n    int maximizeGreatness(vector<int>& nums) {\n        unordered_map<int,int> m;\n        \n        for(int i=0;i<nums.size();i++){\n            if(m.count(nums[i])>0){\n                m[nums[i]]++;\n            }\n            else m[nums[i]]=1;\n        }\n        \n        int ans=0;\n        queue<int> to_remove;\n        \n        while(m.size()>1){\n            ans+=m.size()-1;\n            for(auto& x:m){\n                x.second--;\n                if(x.second==0){\n                    to_remove.push(x.first);\n                }\n            }\n            while(!to_remove.empty()){\n                m.erase(to_remove.front());\n                to_remove.pop();\n            }\n        }\n        return ans;\n    }\n};\n\n```
['Greedy', 'Ordered Map', 'C++']