Two Pointer approach [C++]
Approach\n Describe your approach to solving the problem. \nWe just have to count the number of cases where a[i] < a[j] for all i != j.\nIn my code, I have used
# Approach\n<!-- Describe your approach to solving the problem. -->\nWe just have to count the number of cases where ```a[i] < a[j]``` for all ```i != j```.\nIn my code, I have used 2 pointer approach to achieve the answer.\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution\n{\npublic:\n    int maximizeGreatness(vector<int> &a)\n    {\n        sort(begin(a), end(a));\n        int i = 0;\n        for (int j = 0; j < a.size(); ++j)\n            if (a[i] < a[j])\n                i++;\n        return i;\n    }\n};\n```
['C++']