[C++]  Two pointer
\nclass Solution {\npublic:\n    int maxFrequency(vector<int>& a, int k, int T) {            int n = a.size();\n        sort(a.begin(), a.end());\n\n        int
```\nclass Solution {\npublic:\n    int maxFrequency(vector<int>& a, int k, int T) {            int n = a.size();\n        sort(a.begin(), a.end());\n\n        int ans = 0;\n\n        // Decision 1:      The final result is not equal to a certain element.\n        for (int l = 0, r = 0; r < n; r++) {\n            while (l < r && (a[r]-a[l] > 2*k || (r-l+1) > T)) l++;\n            ans = max(ans, r - l + 1);\n        }\n\n        // Decision 2:      The final result is equal to a certain element.\n        unordered_map<int,int> cnt;\n        for (int i = 0, l = 0, r = 0; i < n; i++) {\n            while (l < i && a[i]-a[l] >  k) cnt[a[l++]]--;\n            while (r < n && a[r]-a[i] <= k) cnt[a[r++]]++;\n            ans = max(ans, min((r-l) - cnt[a[i]], T) + cnt[a[i]]);\n        }\n\n        return ans;\n    }\n};\n\n```
[]