Cpp Solution using set and binary search
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<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\n#define ll long long\nclass Solution {\n    int findCount(vector<int>& nums, int ele, int k){\n        return upper_bound(nums.begin(), nums.end(), ele + k)\n            - lower_bound(nums.begin(), nums.end(), ele - k);\n    }\n    int first(set<int>& s){\n        if(s.empty()) return INT_MIN;\n        return *s.begin();\n    }\npublic:\n    int maxFrequency(vector<int>& nums, int k, int numOperations) {\n        int freq = 0;\n        map<int, int> mp;\n        for(int ele: nums) freq = max(freq, ++mp[ele]);\n        sort(nums.begin(), nums.end());\n\n        set<int> st(nums.begin(), nums.end());\n\n        for(int i = 0; i < nums.size(); i++){\n            st.insert(nums[i] - k);\n            st.insert(nums[i] + k);\n        }\n\n        while(!st.empty()){\n            int ele = *st.begin(); st.erase(ele);\n            // cout << ele << " ";\n            freq = max(freq, mp[ele] + \n                min(numOperations, findCount(nums, ele, k) - mp[ele]));\n        }\n\n        // int cnt = 0;\n        // 1630 83084 84713\n        // for(int ele = nums.front(); ele <= nums.back(); ele++){\n        //     int temp = mp[ele] + \n        //         min(numOperations, findCount(nums, ele, k) - mp[ele]);\n        //     freq = max(freq, temp);\n        //     if(temp == 3) cout << ele << " ";\n        // }\n        // cout << cnt;\n        return freq;\n    }\n};\n```
['C++']