Explained Solution
\n# Code\ncpp []\nclass Solution {\npublic:\n    int maxFrequency(vector<int>& nums, int k, int numOperations) {\n        int n = nums.size();\n        map<int,
\n# Code\n```cpp []\nclass Solution {\npublic:\n    int maxFrequency(vector<int>& nums, int k, int numOperations) {\n        int n = nums.size();\n        map<int, int> freq;\n        vector<pair<int, int>> events;\n        \n        // Build frequency map and event list\n        for (int num : nums) {\n            freq[num]++;\n            events.push_back({num - k, 1});\n            events.push_back({num + k + 1, -1});\n        }\n        \n        // Collect all unique points\n        set<int> points;\n        for (auto& event : events) {\n            points.insert(event.first);\n        }\n        for (auto& p : freq) {\n            points.insert(p.first);\n        }\n\n        // Sort events\n        sort(events.begin(), events.end());\n\n        int idx = 0;\n        int current_overlap = 0;\n        int max_freq = 0;\n        int actual_count = 0;\n        \n        // Traverse each point\n        for (int t : points) {\n            // Process events up to current point t\n            while (idx < events.size() && events[idx].first <= t) {\n                current_overlap += events[idx].second;\n                idx++;\n            }\n            \n            actual_count = freq.count(t) ? freq[t] : 0;\n            int possible_freq = actual_count + min(numOperations, current_overlap - actual_count);\n            max_freq = max(max_freq, possible_freq);\n        }\n\n        return max_freq;\n    }\n};\n```
['C++']