✅C++ || Easy Code
Code\n\nclass Solution {\npublic:\n    int maximizeGreatness(vector<int>& r) {\n        sort(r.begin(),r.end());\n         int n=r.size();\n        if(n==1)retu
# Code\n```\nclass Solution {\npublic:\n    int maximizeGreatness(vector<int>& r) {\n        sort(r.begin(),r.end());\n         int n=r.size();\n        if(n==1)return 0;\n         int i=n-1;\n         int lg=1;\n        int an=0;\n        int ex=0;\n        while(i>=1){\n            if(r[i]==r[i-1])lg++;\n            else{\n                an += min(lg,ex);\n               // cout<<min(lg,ex);\n                ex -= min(lg,ex);\n                ex += lg;\n                lg=1;\n            }\n            i--;\n        }\n        if(r[0]!=r[1]){\n            if(ex)an++;\n        }\n        else {\n             an += min(lg,ex);\n              //  cout<<min(lg,ex);\n                ex -= min(lg,ex);\n                ex += lg;\n        }\n       // cout<<endl;\n            return an;\n        \n    }\n};\n```\n![upvote (3).jpg](https://assets.leetcode.com/users/images/3b9ca2f2-ba97-4bc6-a9bb-56388e10974c_1679303223.2098072.jpeg)\n
['C++']