💹Super Intuitive ||  Easy Thought process || Explained from scratch
Intuition\nOnce sorting the array, if we brute force over each number to try to make every other number equal to this number using k operation or less, this wil
# Intuition\nOnce sorting the array, if we brute force over each number to try to make every other number equal to this number using k operation or less, this will be obvious TLE.\nSuppose we have a candidate number \'x\' which will have maximum frequency after applying some operations, then which number should we apply operations to such that our operations will be used efficiently?\n\nIt\'s number closer to \'x\', isn\'t it!\nNow, this makes sense that all the number closer to \'x\' in our sorted array will be a continuous subarray.\nTherefore, we can use two pointer to look for the longest such subarray. It will be more clear to you in approach section.\n\n\n# Approach\nUsing two pointer i and j, taking mid index of i and j, we will define nums[mid] as our candidate and calculate the required operations to make all the number between i and j equal to nums[mid]. The required operations can be calculated as |(sum of numbers from index i to (mid-1) ) - (mid-i) times nums[mid])| + |(sum of numbers from (mid+1) to j)- (j-mid) times nums[mid] |   \n(Look at the code for clearity).\n\nIf the required operations are smaller or equal to k then we will increase j, else increase i.\nUpdate our answer with max(answer, j-i+1).\n\n# Complexity\n- Time complexity:\n  O(nlog(n))   Since we are sorting the given array.\n\n# Code\n```\nclass Solution {\npublic:\n//foxed\n    int maxFrequencyScore(vector<int>& nums, long long k) {\n        \n        sort(nums.begin(), nums.end());\n        vector<long long> prefix(nums.size()+1,0);\n\n        for(int p=1; p<=nums.size(); p++)\n         prefix[p]= prefix[p-1]+nums[p-1];\n\n        int i=0,j=0, fox=1;\n\n        for(; i<=j && j<nums.size(); )\n        {\n           int mid= (i+j)/2;\n           \n           long long left= prefix[mid]- prefix[i];\n           long long right= prefix[j+1]-prefix[mid+1];\n\n           left= abs(left- 1ll*(mid-i)*nums[mid]);\n           right= abs(right- 1ll*(j-mid)*nums[mid]);\n\n           if(left+right<=k)\n           fox= max(fox, j-i+1), j++;\n           else i++;\n\n           if(i>j)j++;\n\n        }\n\n        return fox;\n    }\n};\n```
['Two Pointers', 'C++']