c++ solution sweep line
Here, sum represents the total count of integers that can be adjusted to \'it\' through either increasing or decreasing.\n\nhash[it] denotes the direct occurren
Here, sum represents the total count of integers that can be adjusted to \'it\' through either increasing or decreasing.\n\nhash[it] denotes the direct occurrences of \'it.\'\n\nThe expression sum - hash[it] gives the number of elements that can actually be increased or decreased.\n\nYou\u2019re allowed to perform only numOperations adjustments.\n\nThus, ans = max(ans, hash[it] + min(sum - hash[it], numOperations));\n\n![image](https://assets.leetcode.com/users/images/82a595f6-57c8-4957-a7a4-be3d9edd888c_1731237020.8411312.png)\n\n```\nclass Solution {\npublic:\n    int maxFrequency(vector<int>& nums, int k, int numOperations) {\n        map<int,int>mp;\n        unordered_map<int,int>hash;\n        set<int>points;\n        for(auto &it:nums){\n            hash[it]++;\n            mp[it-k]++;\n            mp[it+k+1]--;\n            points.insert(it);\n            points.insert(it-k);\n            points.insert(it+k+1);\n        }\n        int ans=1;\n        int sum=0;\n        for(auto &it:points){\n            sum+=mp[it];\n            ans=max(ans,hash[it]+min(sum-hash[it],numOperations));\n        }\n        return ans;\n    }\n};\n```
['C', 'C++']