C++ | Considering boundaries elements | Use Prefix Sum
IntuitionConsidering boundaries elementsCode
# Intuition
Considering boundaries elements
# Code
```cpp []
class Solution {
public:
    int maxFrequency(vector<int>& nums, int k, int ops) 
    {
        sort(nums.begin(),nums.end());
        unordered_map<int,int>count;
        map<int,int>prefix;
        set<int>st;
        for(auto &x:nums)
        {
            count[x]++;
            prefix[x-k]++;
            prefix[x+k+1]--;
            st.insert(x-k);
            st.insert(x+k);
            st.insert(x+k+1);
            st.insert(x);
        }
        int prev=0,res=0;
        for(auto &i:st)
        {
            int curr=prefix[i]+prev;
            res=max(res,min(curr,count[i]+ops));
            prev=curr;
        }
        return res;
    }
};
```
['C++']