Sliding window | Prefix sum | CPP | Sorting
Intuition\n Describe your first thoughts on how to solve this problem. \nWe can easily figure out that we need to sort array and choose a subarray then we need 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe can easily figure out that we need to sort array and choose a subarray then we need to find it\'s median as similar to the 3rd problem of this contest.\n\nSo here are the observations:\n1. Sort the array.\n2. Choose a subarray.\n3. Find the median of that subarray and check if the number of operations is less than \'k\', if so, it\'s a valid answer.\n4. Calculate the maximum among them.     \n\n# Complexity\n- Time complexity: $$O(NlogN)$$\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```\n#define ll long long\nclass Solution {\npublic:\n    int maxFrequencyScore(vector<int>& nums, long long k) {\n        ll mx = 0, l = 0, n = nums.size();\n        sort(nums.begin(), nums.end());\n        vector<ll> pre(n+1, 0);\n        for(int i = 0; i < n; ++i) {\n            pre[i+1] = pre[i] + nums[i];\n        } \n        for(ll r = 0; r < n; ++r) {\n            ll mi = (l+r)/2;\n            ll md = nums[mi];\n            ll lSum = md * (mi-l) - (pre[mi-1+1] - pre[l-1+1]);\n            ll rSum = pre[r+1] - pre[mi+1] - (md * (r-mi));\n            if(lSum + rSum > k) {\n                l++;\n            }\n            mx = max(mx, r-l+1);\n        }\n        return mx;\n    }   \n};\n```
['Sliding Window', 'Sorting', 'Prefix Sum', 'C++']