Easy to understand beginner solution using sliding window
Intuition\n# Use the sliding window to find max subarray which can be make equal to its median\n\n# Approach\n Describe your approach to solving the problem. \n
# Intuition\n# **Use the sliding window to find max subarray which can be make equal to its median**\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(NLOGN)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    bool check(int i,int j,long long sum,vector <int> &nums,vector <long long> &preSum,long long k){\n            int len = (i-j+1);\n           // cout<<i<<" "<<j<<endl;\n            long long mean;\n            if(len%2)\n            mean = nums[(i+j)/2];\n            else\n            {\n                int mid = (i+j)/2;\n                mean = (nums[mid]+nums[mid+1])/2;\n            }\n\n            int ind = upper_bound(nums.begin(),nums.end(),mean)-nums.begin();\n            ind-=1;\n            long long left = preSum[ind]-((j>0)?preSum[j-1]:0);\n            int lenL = ind-j+1;\n            long long right = preSum[i] - preSum[ind];\n            int lenR = i-ind;\n\n            long long reqLeft = abs(mean*lenL - left);\n            long long reqRight = abs(mean*lenR - right);\n\n            // 3 0\n            // 2 3 2 1\n          //  cout<<reqLeft<<" "<<lenL<<" "<<reqRight<<" "<<lenR<<endl;\n            if(reqLeft+reqRight<=k) return 1;\n            return 0;\n\n    }\n    int maxFrequencyScore(vector<int>& nums, long long k) {\n         sort(nums.begin(),nums.end());\n        int n = nums.size();\n        vector <long long> preSum(n,0);\n        preSum[0] = nums[0];\n        for(int i=1;i<n;i++)\n        {\n            preSum[i] = preSum[i-1] + 1LL*nums[i];\n        }\n        int ans = 0;\n        long long sum = 0;\n        for(int i=0,j=0;i<nums.size();i++){\n            sum+=nums[i];\n            while(!check(i,j,sum,nums,preSum,k)) sum-=nums[j++];\n            ans = max(ans,i-j+1);\n        }\n        return ans;\n    }\n};\n```
['Sliding Window', 'C++']