Binary Search: Evolution from Smaller Constraints to Larger Constraints
Smaller constraints\npython3 []\nclass Solution:\n    def maxFrequency(self, nums: List[int], k: int, numOperations: int) -> int:\n        counter = Counter(num
# Smaller constraints\n``` python3 []\nclass Solution:\n    def maxFrequency(self, nums: List[int], k: int, numOperations: int) -> int:\n        counter = Counter(nums)\n        nums.sort()\n        ans = 1\n        for i in range(1, max(nums) + 1):\n            left = bisect_left(nums, i-k)\n            right = bisect_right(nums, i+k)\n            total = right-left\n            ans = max(ans, min(numOperations, total - counter[i]) + counter[i])\n        return ans\n        \n```\n\n# Larger constrainsts\n```python3 []\nclass Solution:\n    def maxFrequency(self, nums: List[int], k: int, numOperations: int) -> int:\n        counter = Counter(nums)\n        nums.sort()\n        ans = 1\n        def compute(val):\n            left = bisect_left(nums, val-k)\n            right = bisect_right(nums, val+k)\n            total = right-left\n            return min(numOperations, total - counter[val]) + counter[val]\n        \n        for n in nums:\n            ans = max(ans, compute(n), compute(n-k), compute(n+k))             \n        \n        return ans\n        \n```
['Python3']