Very Simple TreeMap Solution for Q2 And Q3 in Java (O(NlogN))
Intuition\n Describe your first thoughts on how to solve this problem. \n1. Use TreeMap for sorted keys ( used for range )\n# Approach\n Describe your approach 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n1. Use TreeMap for sorted keys ( used for range )\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Use the normal freq Map to store the frequecny of each elem\n2. Use the treeMap to initialise each elem and also set the start and end point (like after which val we cant do +k and -k )\n    - decrement by -1 for  **num+k+1**\n    - increment by +1 for  **num-k**\n    - this ensure the start and end points when fetching the entries \n3. Fetch Each Entry of TreeSet and check whether the freqMap have that entry to maximize the overall freq\n# Complexity\n- Time complexity:O(nlogn)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n    public int maxFrequency(int[] nums, int k, int numOperations) {\n        Map<Integer, Integer> freqMap = new HashMap<>();\n        TreeMap<Integer, Integer> prefixMap = new TreeMap<>();\n        for (int num : nums) {\n            freqMap.put(num, freqMap.getOrDefault(num, 0) + 1);\n            prefixMap.put(num, prefixMap.getOrDefault(num, 0));\n            prefixMap.put(num + k + 1, prefixMap.getOrDefault(num + k + 1, 0) - 1);\n            prefixMap.put(num - k, prefixMap.getOrDefault(num - k, 0) + 1);\n        }\n        int maxFreq = 0, prefixSum = 0;\n        for (Map.Entry<Integer, Integer> entry : prefixMap.entrySet()) {\n            prefixSum += entry.getValue();\n            int freq = freqMap.getOrDefault(entry.getKey(), 0);\n            maxFreq = Math.max(maxFreq, Math.min(prefixSum - freq, numOperations) + freq);\n        }\n        return maxFreq;\n    }\n}\n\n```
['Ordered Map', 'Java']