🔥BinarySearch on ANS || ⚡SlidingWindow(FixedSize) || 🌟Median || ✅Sorting
Connect with me on LinkedIn : https://www.linkedin.com/in/aditya-jhunjhunwala-51b586195/\n\n# Complexity\n\n- Time complexity:\nO(n log n)\n\n- Space complexity
## Connect with me on LinkedIn : https://www.linkedin.com/in/aditya-jhunjhunwala-51b586195/\n\n# Complexity\n```\n- Time complexity:\nO(n log n)\n\n- Space complexity:\nO(n)\n```\n\n# Code\n## Please Upvote if it helps\uD83E\uDD17\n```\nclass Solution {\npublic:\n    bool helper(int freq, vector<int>& nums, long long k, vector<long>& prefix, int n){\n        for(int i = 0 ; i <= n - freq ; i++){\n            int j = i + freq - 1;\n            int median = (freq & 1) ? nums[(i + j) / 2] : (nums[(i + j) / 2] + nums[(i + j + 2) / 2]) / 2;\n            int ind = (i + j) / 2;\n            long lft_sum = (long)median * (ind - i + 1) - (prefix[ind] - ((i - 1 >= 0) ? prefix[i - 1] : 0));\n            long rgt_sum = (prefix[j] - prefix[ind]) - ((long)median * (j - ind));\n            if(lft_sum + rgt_sum <= k)\n                return true;\n        }\n        return false;\n    }\n    \n    int maxFrequencyScore(vector<int>& nums, long long k) {\n        int n = nums.size(), ll = 1, ul = n , mid = 0, maxi = 0;\n        long prefixSum = 0;\n        sort(nums.begin(), nums.end());\n        vector<long> prefix;\n        for(auto it : nums){\n            prefixSum += it;\n            prefix.push_back(prefixSum);\n        }\n        while(ll <= ul){\n            mid = (ll + ul) >> 1;\n            if(helper(mid, nums, k, prefix, n)){\n                ll = mid + 1;\n                maxi = mid;\n            }\n            else\n                ul = mid - 1;   \n        }\n        return maxi;\n    }\n};\n```
['Binary Search', 'Sliding Window', 'Sorting', 'C++']