Prefix sum | Line sweep Algo | beginner friendly
Intuition\n Describe your first thoughts on how to solve this problem. \nwe have two maps for storing the frequency of actual number and another for calculating
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nwe have two maps for storing the frequency of actual number and another for calculating the frequency of range of numbers, please go through the commented code. \n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $$O(nlogn)$$ we are using the ordered map\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int maxFrequency(vector<int>& nums, int k, int numOperations) {\n        //this is use for storing the frequence of each element\n        map<int, int> numWithoutChange;\n\n        //this is use for storing the frequency after add or subtract k from the original number\n        map<int, int> numWithChange;\n        int res = 0, cur = 0;\n        for(int i: nums){\n            numWithoutChange[i]++;\n            numWithChange[i];  //this is required for only entry of the actual number\n            numWithChange[i-k]++;\n            numWithChange[i+k+1]--;\n        }\n        for(auto &[num, freq] : numWithChange){\n            cur += freq;\n            //we have the fixed number of operations so we can do only numOperations\n            res = max(res, numWithoutChange[num] + min(cur - numWithoutChange[num], numOperations));\n        }\n        return res;\n    }\n};\n```
['C++']