Brute Force on All Possible Values
Code\ncpp []\n#define ll long long\nclass Solution {\npublic:\n    int maxFrequency(vector<int>& nums, int k, int numOperations) {\n        ll n = nums.size();\
# Code\n```cpp []\n#define ll long long\nclass Solution {\npublic:\n    int maxFrequency(vector<int>& nums, int k, int numOperations) {\n        ll n = nums.size();\n        sort(nums.begin(), nums.end());\n        ll e = nums.back();\n        ll s = nums[0];\n        ll ans = 0;\n        \n        map<ll, ll> mp;\n        for(auto &i : nums) mp[i]++;\n\n        vector<ll> v;\n        for(auto &i : nums){\n            v.push_back(i - k);\n            v.push_back(i + k);\n            v.push_back(i);\n        }\n        \n        for(int i = 0; i < v.size(); i++){\n            ll val = v[i];\n            \n            ll idx1 = lower_bound(nums.begin(), nums.end(), val - k) - nums.begin();\n            ll idx2 = upper_bound(nums.begin(), nums.end(), val + k) - nums.begin();\n            ll times = (idx2 - idx1);\n            ll red = mp[val];\n            times -= red; \n\n            ll poss = red + min((ll)numOperations, times);\n            ans = max(ans, red + min((ll)numOperations, times));\n        }\n        \n        return ans;\n    }\n};\n```
['C++']