Rust | Sliding Window | 18 ms
\n\nimpl Solution {\n    pub fn max_frequency_score(mut nums: Vec<i32>, k: i64) -> i32 {\n        nums.sort_unstable();\n        let (mut i, mut max_length, mut
\n```\nimpl Solution {\n    pub fn max_frequency_score(mut nums: Vec<i32>, k: i64) -> i32 {\n        nums.sort_unstable();\n        let (mut i, mut max_length, mut curr_cost, n) = (0, 0, 0, nums.len());\n\n        (0..n).for_each(|j| {\n            curr_cost += nums[j] as i64 - nums[(i + j) / 2] as i64;\n\n            while curr_cost > k {\n                curr_cost -= nums[(i + j + 1) / 2] as i64 - nums[i] as i64;\n                i += 1\n            }\n\n            max_length = max_length.max((j - i + 1) as i32)\n        });\n\n        max_length\n    }\n}\n```
['Rust']