Sort + 2 pointers
Intuition\nSort the array and find every possible higher element for each element.\n\n# Approach\nSort the array. Create two  pointers. For every possible eleme
# Intuition\nSort the array and find every possible higher element for each element.\n\n# Approach\nSort the array. Create two  pointers. For every possible element find higher one.\n\n# Complexity\n- Time complexity:\nO(N*Log(N))\n\n- Space complexity:\nO(1)\n\n# Code\n```\n/**\n * @param {number[]} nums\n * @return {number}\n */\nvar maximizeGreatness = function(nums) {\n    nums.sort((a,b) => a - b)\n    let res = 0;\n    let j = 1;\n    for(let i = 0; i < nums.length; i++){\n        while(j < nums.length && nums[j] <= nums[i]){\n            j++;\n        }\n        if(j < nums.length && nums[j] > nums[i]){\n            j++;\n            res++;\n        }\n    }\n    \n    return res\n};\n```
['JavaScript']