[Golang] Sliding Window + Prefix Sum
Code\n\nfunc maxFrequencyScore(nums []int, k int64) int {\n  var res int\n  sort.Ints(nums)\n  psum := make([]int64, len(nums)+1)\n  for i := 1; i <= len(nums);
# Code\n```\nfunc maxFrequencyScore(nums []int, k int64) int {\n  var res int\n  sort.Ints(nums)\n  psum := make([]int64, len(nums)+1)\n  for i := 1; i <= len(nums); i++ {\n    psum[i] = psum[i-1] + int64(nums[i-1])\n  }\n  left := 0\n  for right := 0; right < len(nums); right++ {\n    for left < right && compute(nums, psum, left, right) > k {\n      left++\n    }\n    res = max(res, right - left + 1)\n  }\n  return res\n}\n\nfunc compute(nums []int, psum []int64, left, right int) int64 {\n  mid := left + (right-left+1)/2\n  // We need to find the number of ops needed to make nums[left:right+1] equal to\n  // nums[mid]\n  // Let\'s divide this to two; nums[left:mid+1] and nums[mid+1:right+1]\n  var leftOps, rightOps int64\n  leftOps = int64(nums[mid] * (mid-left+1)) - (psum[mid+1] - psum[left])\n  if mid != right {\n    rightOps = (psum[right+1] - psum[mid+1]) - int64(nums[mid] * (right - mid))\n  }\n  ops := leftOps + rightOps\n  return ops\n}\n```
['Sliding Window', 'Prefix Sum', 'Go']