Overcomplicated sliding window (R-70%+, M-5%+)
Complexity\n- Time complexity: O(n * log n)\nn - length of input array nums\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n)\n Add your s
# Complexity\n- Time complexity: **O(n * log n)**\n**n** - length of input array `nums`\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: **O(n)**\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n    def maxFrequencyScore(self, nums: List[int], k: int) -> int:\n        if k == 0:\n            # Maximum sequence of equal values.\n            return max(Counter(nums).values())\n        nums.sort()\n        prefixes: list[int] = [0 for _ in range(len(nums))]\n        suffixes: list[int] = [0 for _ in range(len(nums))]\n        for x in range(1, len(nums)):\n            prefixes[x] = prefixes[x - 1] + nums[x - 1]\n        for x in range(len(nums) - 2, -1, -1):\n            suffixes[x] = suffixes[x + 1] + nums[x + 1]\n        # Leftmost, rightmost indexes of sliding window.\n        left: int = 0\n        right: int = 0\n        max_score: int = 1\n        # Expand.\n        while right < len(nums) - 1:\n            right += 1\n            median: int = (left + right) // 2\n            target: int = nums[median]  # value we want in the whole subarray (left -> right, inclusive)\n            # Operations to get subarray in balance, i.e make all values equal to target:\n            # (sum of values we need in {left -> median, median not included}) - (what we already have)) +\n            # + (what we already have) - (sum of values we need in {median -> right, median not included})\n            balance_cost: int = ((target * (median - left) - (prefixes[median] - prefixes[left]))\n                                + (suffixes[median] - suffixes[right] - target * (right - median)))\n            # Shrink, until window is correct.\n            while balance_cost > k:\n                left += 1\n                median = (left + right) // 2\n                target = nums[median]\n                balance_cost = ((target * (median - left) - (prefixes[median] - prefixes[left]))\n                                + (suffixes[median] - suffixes[right] - target * (right - median)))\n            max_score = max(max_score, right + 1 - left)  # +1 for 0-indexed.\n        return max_score\n```
['Sliding Window', 'Sorting', 'Python3']