[Python] ⚡ binary search
python\nclass Solution:\n    def maximizeGreatness(self, nums: List[int]) -> int:\n        count = defaultdict(int)\n        for n in nums:\n            count[n
```python\nclass Solution:\n    def maximizeGreatness(self, nums: List[int]) -> int:\n        count = defaultdict(int)\n        for n in nums:\n            count[n] += 1\n        arr = sorted(count.keys())\n        \n        t = 0\n        for n in nums:\n            i = bisect.bisect(arr, n)\n\n            while i < len(arr):\n                n = arr[i]\n                if count[n] > 0:\n                    count[n] -= 1\n                    \n                    # next bisect optimization\n                    if count[n] == 0:\n                        if i > 0:\n                            arr[i] = arr[i - 1]\n                        else:\n                            arr[i] = 0\n\n                    t += 1\n                    break\n                \n                i += 1\n\n        return t\n```
['Binary Tree']