Easy Binary Search + sliding window solution
Intuition\n Describe your first thoughts on how to solve this problem. \nKind of same as LeetCode 1838\n\n# Approach\n Describe your approach to solving the pro
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nKind of same as LeetCode 1838\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n    1. We are to make maximum elements equal to same number using at max k operation\n\n    2. So we can say in an array of size n....at most we can make n elements same and atleast 1 freq of any one element  \n\n    3. So what we can do is binary search on size space ,i.e, our solution will lie between [1,n] taking O(logN) time \n\n    4. As for each value of mid we will check if this all the value in that window can be made equal, which is done using sliding window, taking O(n)\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n    O(nLogn)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n    O(n)\n\n# Code\n```\n#define ll long long int\nclass Solution {\npublic:\n    int maxFrequencyScore(vector<int>& nums, long long k) {\n        sort(nums.begin(),nums.end());\n\n        int n = nums.size(), l = 1, r = n, ans = 1;\n        vector<ll>preSum(n,0);\n        preSum[0] = nums[0];\n        for(int i = 1; i<n; i++){\n            preSum[i] = nums[i] + preSum[i-1]; \n        }\n\n        while(l<=r){\n            int mid = l + (r-l)/2;\n            int lenToTry = mid;\n            bool isPossible = 0;\n\n            for(int i = 0, j=0; i<n; i++){\n                if(i-j+1 == lenToTry){\n                    ll medianIndex = (i+j)/2;\n                    ll leftSum = preSum[medianIndex] - preSum[j] + nums[j];\n                    ll leftCount = medianIndex - j + 1;\n\n                    ll rightSum = preSum[i] - preSum[medianIndex] + nums[medianIndex];\n                    ll rightCount = i-medianIndex+1;\n\n                    ll sumReq = (nums[medianIndex]*leftCount - leftSum) + (rightSum - nums[medianIndex]*rightCount);     \n                    j++;\n                    if(sumReq<=k){\n                        // if even a single subarray is found \n                        isPossible = 1;\n                        break;\n                    }\n                }\n            }\n            if(isPossible){\n                //then try for greater size\n                ans = lenToTry;\n                l = mid + 1;\n            }else{\n                r = mid-1;\n            }\n        }\n        return ans;\n    }\n}; \n```
['C++']