Binary Search for the max window length
Complexity\n- Time complexity: O(n * log_2n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:O(1)\n Add your space complexity here, e.g. O(n) 
# Complexity\n- Time complexity: $$O(n * log_2n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:$$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    using ll = long long;\n    \n    bool isPossible(int n, long long k, long long mi, const vector<int>& nums){        \n        ll leftSum = 0, rightSum = 0, lc = 0, rc = 0;\n        ll median = mi >> 1;\n        for(int i = 0; i < mi; i++){\n            if(i <= median){\n                leftSum += nums[i];\n                lc++;\n            }\n            else{\n                rc++;\n                rightSum += nums[i];\n            }\n        }\n        \n        ll ops = (nums[median] * lc - leftSum) + (rightSum - nums[median] * rc);\n        if(ops <= k) return true;\n        \n        for(int i = 1; i < n - mi + 1; i++){\n            ll midval = nums[i + median];\n            leftSum += midval - nums[i - 1];\n            rightSum += nums[i + mi - 1] - midval;\n            ops = (midval * lc - leftSum) + (rightSum - midval * rc);\n            if(ops <= k) return true;\n        }\n        \n        return false;\n    }\n    \n    int maxFrequencyScore(vector<int>& nums, long long k) {\n        long long n = nums.size();\n        sort(nums.begin(), nums.end());\n        \n        long long lo = 1, hi = n, best = 1, mi;\n        while(lo <= hi){\n            mi = (lo + hi) >> 1;\n            if(isPossible(n, k, mi, nums)){\n                best = mi;\n                lo = mi + 1;\n            }else{\n                hi = mi - 1;\n            }\n        }\n        \n        return best;\n    }\n};\n```
['C++']