Difference Array Technique
Prerequisite\n Difference Array Method\n# Approach\n Describe your approach to solving the problem. \n For each element, the possible range where it can be conv
# Prerequisite\n* Difference Array Method\n# Approach\n<!-- Describe your approach to solving the problem. -->\n* For each element, the possible range where it can be converted to is [el - k, el + k].\n* So we can use difference array method to store the freq of elements in that range in a map / array.\n* But looking at the constraints, we won\'t be able to iterate through each element in overall range. \n* So by observation, we can se that changes in difference array take place only at th end points of range of each element i.e at (el - k) and (el + k + 1) , so we can iterate at that points only .\n# Complexity\n- Time complexity: $$O(N*logN)$$\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```cpp []\nclass Solution {\npublic:\n    int maxFrequency(vector<int>& nums, int k, int numOperations) {\n        map<int, int>difArray, freq;\n        int low = 2e9, high = -2e9, ans = 1, prevSum = 0;\n        for(int i : nums){\n            freq[i] ++;\n            difArray[i - k] ++;\n            difArray[i + k + 1] --;\n            difArray[i] += 0;\n        }\n        for(auto it : difArray){\n\n            it.second += prevSum;\n            prevSum = it.second;\n            int extra = it.second - freq[it.first];\n            extra = min(extra, numOperations);\n            ans = max(ans, extra + freq[it.first]);\n        }\n        return ans;\n    }\n};\n```
['C++']