Sliding window beats 100% python solution
Intuition\n Describe your approach to solving the problem. \n\nIf there could be a subarray where all the elements are same that would be the answer. We need to
# Intuition\n<!-- Describe your approach to solving the problem. -->\n\nIf there could be a subarray where all the elements are same that would be the answer. We need to find that maximum subarray where all the elements are same after k operations. We would use the sliding window to find a subarray where all the elements can be same. For a subaaray, `arr[i,i+1,....,j]`, what should be number be so that all the elements are equal to that number. The answer would be median of the subarray.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe will sort the array first. Then we will have 2 pointers representing the subarray. At each iteration we will add the difference between the element and the median element of the subarray. When moving forward we need to keep in mind that median might change. For example for suarray `1,2,..10` the median would `5`. But for `2,3,...10`, it would be `6`. So we need to add and subtract from `k` accordingly. Please see the solution for more clarity.\n\n# Complexity\n- Time complexity:\n`O(long n)` because we need to sort array.\n\n# Code\n```\nclass Solution:\n    def maxFrequencyScore(self, nums: List[int], k: int) -> int:\n        nums.sort()\n        i = 0\n        j = 0\n        c = 0\n        ans = 0\n        while j < len(nums):\n            m = i + (j-i) // 2\n            c += nums[j] - nums[m]\n            while c > k and i < m:\n                c -= abs(nums[(i + j + 1) // 2] - nums[i])\n                i+=1\n            ans = max(ans, j - i + 1)\n            j+=1\n        return ans\n\n```
['Python3']