[C++] Binary search solution, short and clean
Propose one of the element in nums to be the number with maximum frequency.\n\nFor each proposed value nums[i], count how many need 0 changes, and count how man
Propose one of the element in ```nums``` to be the number with maximum frequency.\n\nFor each proposed value ```nums[i]```, count how many need 0 changes, and count how many need 1 operation and store this in diff\n\nIf we suppose a number with the maximum frequncy which is not in ```nums``` then the maxium result would be ```numOperations```.\nWe suppose on the sorted array that the minimum value is nums[i] to which we can add a value in (0, k) and we determine the maximum value from which we can subtract a value (0, k), because each value need to be modified.\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int maxFrequency(vector<int>& nums, int k, int numOp) {\n        sort(nums.begin(), nums.end());\n        int res = 0, n = nums.size();\n        if (k == 0) {\n            for (int i = 0; i < n; i++) {\n                int j = i + 1;\n                for (; j < n && nums[i] == nums[j]; j++);\n                res = max (j - i, res);\n            }\n            return res;\n        }\n        \n        for (int i = 0; i < n; i++) {\n            int j = i + 1;\n            for (; j < n && nums[i] == nums[j]; j++);\n            auto bg = upper_bound(nums.begin(), nums.end(), nums[i] + k);\n            auto low = lower_bound(nums.begin(), nums.end(), nums[i] - k);\n            int indbg = distance(nums.begin(), bg);\n            int indlow = distance(nums.begin(), low);\n            int diff = indbg - indlow - (j - i);\n            res = max(min(numOp, diff) + j - i, res);\n        }\n        if (res > numOp)\n            return res;\n        //proposed value is not in nums \n        vector<int> mnv;\n        for (int i = 0; i < n; i++) {\n            mnv.push_back(nums[i] - k);\n        }\n    \n        for (int i = 0; i < n; i++) {\n            auto bg = upper_bound(mnv.begin(), mnv.end(), nums[i] + k);  \n            int indbg = distance(mnv.begin(), bg);\n            int diff = indbg - i;\n            res = max(min(numOp, diff), res);\n        }\n        return res;\n    }\n};\n```
['C++']