Simple solution only using upper bound and lower bound in C++
Intuition\n Describe your first thoughts on how to solve this problem. \nApply upperbound and lower bound you have only two option either you can make all eleme
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nApply upperbound and lower bound you have only two option either you can make all elements equal to some elemnet that is present in array or you can make any other element that is not present so find the lowest and uppermost index that can be included to apply operations such that all element can be converted into one \n\n# Approach\n<!-- Describe your approach to solving the problem. -->\ncode is self explanatory using oly upperbound and lowerbound \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\ntypedef long long ll;\nclass Solution {\npublic:\n    int maxFrequency(vector<int>& nums, int k, int numOperations) {\n        sort(nums.begin(), nums.end()); \n        set<int>st;\n        int n=nums.size();\n        for(int i=0;i<n;i++){\n            st.insert(nums[i]);\n        }\n        int mx=1;\n        for(auto & it:st){\n            int num=it;\n            auto itu=upper_bound(nums.begin(),nums.end(),it); itu--;\n            int up=itu-nums.begin();\n            auto itl=lower_bound(nums.begin(),nums.end(),it);\n            int lo=itl-nums.begin();\n            int lon=lower_bound(nums.begin(),nums.end(),it-k)-nums.begin();\n            int upn=(--upper_bound(nums.begin(),nums.end(),it+k))-nums.begin();\n            mx=max(mx,(up-lo+1)+min(numOperations,upn-up+lo-lon));\n            int ex=lower_bound(nums.begin(),nums.end(),it-2*k)-nums.begin();\n            mx=max(mx,min(up-ex+1,numOperations));\n        }\n        return mx;\n    }\n};\n```
['C++']