Binary Search + Map Approach (In-contest solution)
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n$O(n*logn)$\n\n- Space complexity:\n$$O(n)$$\n\n# Code\n```java []\nclass Solution {\n    public int calcf(int i, int n, int[] nums, int numOperations, Map<Integer, Integer> map, int k){\n        int t1 = i - k;\n        int t2 = i + k;\n        int l = 0;\n        int r = n - 1;\n        int ans1 = -1;\n        int ans2 = -1;\n        while(l <= r){\n            int mid = l + (r - l) / 2;\n            if(nums[mid] >= t1){\n                r = mid - 1;\n            }\n            else l = mid + 1;\n        }\n        ans1 = l;\n        l = 0;\n        r = n - 1;\n        while(l <= r){\n            int mid = l + (r - l) / 2;\n            if(nums[mid] <= t2){\n                l = mid + 1;\n            }\n            else r = mid - 1;\n        }\n        ans2 = r;\n        if(ans1 == n || ans2 == -1)return 0;\n        else{\n            int f = (ans2 - ans1 + 1);\n            int op = f - map.getOrDefault(i, 0);\n            if(op > numOperations)op = numOperations;\n            return op + map.getOrDefault(i, 0);\n        }\n    }\n    \n    public int maxFrequency(int[] nums, int k, int numOperations) {\n        Arrays.sort(nums);\n        int n = nums.length;\n        HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();\n        int maxf = 1;\n        int maxel = 1;\n        int minel = Integer.MAX_VALUE;\n        for(int num : nums){\n            map.put(num, map.getOrDefault(num, 0) + 1);\n            maxf = Math.max(maxf, map.get(num));\n            maxel = Math.max(maxel, num);\n            minel = Math.min(minel, num);\n        }\n        if(k == 0 || nums.length == 1 || numOperations == 0)return maxf;\n        for(int num : nums){\n            maxf = Math.max(maxf, calcf(num, n, nums, numOperations, map, k));\n            maxf = Math.max(maxf, calcf(num + k, n, nums, numOperations, map, k));\n            maxf = Math.max(maxf, calcf(num - k, n, nums, numOperations, map, k));\n        }\n        return maxf;\n    }\n}\n```
['Java']