Java Binary Search
\njava\nclass Solution {\n    public int maxFrequency(int[] nums, int k, int numOperations) {\n        Arrays.sort(nums);\n        Map<Integer, Integer> freq = 
\n```java\nclass Solution {\n    public int maxFrequency(int[] nums, int k, int numOperations) {\n        Arrays.sort(nums);\n        Map<Integer, Integer> freq = new HashMap<>();\n        for (int num : nums) {\n            freq.put(num, freq.getOrDefault(num, 0)+1);\n        }\n        int max = 0;\n        for (int i = 0;i < nums.length;i++) {\n            int lowerBound = binarySearchLower(nums, nums[i]-k);\n            int upperBound = binarySearchUpper(nums, nums[i]+k)+1;\n            int totalOfCurrentNumber = freq.get(nums[i]);\n            max = Math.max(max, totalOfCurrentNumber);\n            int onesCanApplyOperationOn = upperBound - lowerBound - totalOfCurrentNumber;\n            //System.out.println("NUM: " + nums[i] + ": TOTAL OPS CAN BE APPLIED" + onesCanApplyOperationOn + " : " + "LOWER: " + lowerBound + ": UPPER: " + upperBound);\n            max = Math.max(max, Math.min(onesCanApplyOperationOn, numOperations) + totalOfCurrentNumber);\n            \n            // meet at some number check\n            lowerBound = binarySearchLower(nums, nums[i] - k * 2);\n            max = Math.max(max, Math.min(i - lowerBound + 1, numOperations));\n            //System.out.println("MEET AT SOME NUMBER LEN: " + Math.min(i - lowerBound + 1, numOperations));\n            \n        }\n        return max;\n    }\n    private int binarySearchUpper(int[] nums, int target) {\n        int left = 0;\n        int right = nums.length-1;\n        int ans = 0;\n        while (left <= right) {\n            int mid = (left + right) / 2;\n            \n            if (nums[mid] <= target) {\n                ans = mid;\n                left = mid + 1;\n            } else {\n                right = mid - 1;\n            }\n        }\n        return ans;\n        \n    }\n    \n    private int binarySearchLower(int[] nums, int target) {\n        int left = 0;\n        int right = nums.length;\n        \n        while (left < right) {\n            int mid = (left + right) / 2;\n            \n            if (nums[mid] < target) {\n                left = mid + 1;\n            } else {\n                right = mid;\n            }\n        }\n        return left;\n        \n    }\n}\n\n\n```
['Java']