Python | Binary Search | O(nlogn)
Code\n\nfrom collections import Counter\nclass Solution:\n    def maxFrequencyScore(self, nums: List[int], k: int) -> int:\n        if k == 0:\n            retu
# Code\n```\nfrom collections import Counter\nclass Solution:\n    def maxFrequencyScore(self, nums: List[int], k: int) -> int:\n        if k == 0:\n            return max(Counter(nums).values())\n        n = len(nums)\n        nums.sort()\n        def check(w):\n            cur = 0\n            for i in range(w):\n                cur += abs(nums[i] - nums[w//2])\n            mi = w//2\n            i = 0\n            j = w-1\n            res = cur\n            for j in range(w,len(nums)):\n                delta = nums[mi+1] - nums[mi]\n                mi += 1\n                cur += (w//2 + 1)*delta -(w//2 +(0 if w%2 else -1))*delta - (nums[mi] - nums[i]) + nums[j] - nums[mi]\n                i += 1\n                res = min(res, cur)\n            return res <= k\n        left, right = 0, n \n        while left < right:\n            mid = (left + right + 1)//2\n            if check(mid):\n                left = mid \n            else:\n                right = mid - 1\n        return left \n    \n            \n\n\n\n```
['Python3']