Sliding Windows + tricky shift of window
Complexity\n- Time complexity: O(n \cdot \log(n))\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n)\n Add your space complexity here, e.g.
# Complexity\n- Time complexity: $$O(n \\cdot \\log(n))$$\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```python3 []\nclass Solution:\n    def maxFrequency(self, nums: List[int], k: int, numOperations: int) -> int:\n        nums.sort()\n        n = len(nums)\n        \n        c = Counter(nums)\n        data = sorted(c.keys()) \n                \n        def get_shift_by_elem(index):\n            if index == len(data) - 1:\n                return float(\'inf\')\n            return data[index + 1]\n        \n        def get_shift_to_right_border(elem, r):\n            if r == n:\n                return float(\'inf\')\n            return (nums[r] - nums[r - 1]) + elem\n        \n        def get_shift_to_left_border(elem, l):\n            if l == n:\n                return float(\'inf\')\n            # (nums[l] + k) can be equal to elem\n            return max(nums[l] + k, elem + 1)\n        \n        def get_next_elem(elem, index, l, r):\n            next_1 = get_shift_by_elem(index)\n            next_2 = get_shift_to_right_border(elem, r)\n            next_3 = get_shift_to_left_border(elem, l)\n            \n            result = min(next_1, next_2, next_3)\n            if result == next_1:\n                return result, index + 1\n            return result, index\n\n        result = 0        \n        l = r = window_size = 0\n\n        index = 0\n        elem = nums[index]\n\n        while True:\n            # move left border of window\n            while nums[l] < elem - k:\n                window_size -= 1\n                l += 1\n            \n            # move right border of window\n            while r != n and nums[r] <= elem + k:\n                window_size += 1\n                r += 1\n                \n            # update result\n            current = c[elem] + min(numOperations, window_size - c[elem])\n            result = max(result, current)\n            \n            # shift to next element\n            elem, index = get_next_elem(elem, index, l, r)\n            if elem > nums[-1]:\n                break\n\n        return result\n```
['Sliding Window', 'Sorting', 'Counting', 'Python3']