Binary Search on answer - C++
Code\ncpp []\nclass Solution {\npublic:\n    bool is_possible(int window,vector<long long>& prefix,long long k,vector<int> &nums){\n        int left = 0; int ri
# Code\n```cpp []\nclass Solution {\npublic:\n    bool is_possible(int window,vector<long long>& prefix,long long k,vector<int> &nums){\n        int left = 0; int right = window;\n        int n = prefix.size();\n        while(right < n){\n            int mid = (left + right + 1) >> 1;\n            long long left_sum = prefix[mid] - prefix[left];\n            long long right_sum = prefix[right] - prefix[mid];\n            if(((((long long)nums[mid - 1] * (mid - left)) - left_sum) + (right_sum - ((long long)nums[mid-1]*(right - mid)))) <= k ) return true;\n            right++; left++;\n        }\n        return false;\n    }\n    int maxFrequencyScore(vector<int>& nums, long long k) {\n        int n = nums.size();\n        sort(nums.begin(),nums.end());\n        vector<long long> prefix(1);\n        long long sum = 0;\n        for(int i=0;i<n;i++){\n            sum += nums[i];\n            prefix.push_back(sum);\n        }\n        int left = 1; int right = n;\n        while(left <= right){\n            int mid = left + ((right - left) >> 1);\n            if(is_possible(mid,prefix,k,nums)) left = mid + 1;\n            else right = mid - 1;\n        }\n        return right;\n    }\n};\n```
['Binary Search', 'Sliding Window', 'Prefix Sum', 'C++']