:: Kotlin :: Sliding Window & Median
\nclass Solution {\n    fun maxFrequencyScore(nums: IntArray, k: Long): Int {\n        Arrays.sort(nums)\n\n        var result = 1\n        var cost = 0L\n     
```\nclass Solution {\n    fun maxFrequencyScore(nums: IntArray, k: Long): Int {\n        Arrays.sort(nums)\n\n        var result = 1\n        var cost = 0L\n        var left = 0\n\n        for (right in 0 until nums.size) {\n            cost += nums[right] - nums[((right - 1) + left + 1) / 2]\n\n            while (cost > k) {\n                cost -= nums[(right + left + 1) / 2] - nums[left++]\n            }\n            result = maxOf(result, right - left + 1)\n        }\n\n        return result\n    }\n}\n```
['Kotlin']