Optimized Approach: Maximize Frequency with Limited Operations 🚀
Intuition\nThe goal is to find the maximum frequency of a number in the array by performing at most k operations, where each operation increases or decreases a 
# Intuition\nThe goal is to find the maximum frequency of a number in the array by performing at most k operations, where each operation increases or decreases a number. Sorting the array helps us focus on contiguous elements, as increasing smaller numbers to match a target minimizes the operations needed.\n# Approach\n- 1, Sort the Array: Sorting the array ensures that consecutive numbers are close in value, making it easier to analyze frequency with minimal operations.\n- 2, Sliding Window Technique:\nUse a sliding window to explore subarrays that can be converted to the same number using at most k operations.\nExpand the window by moving right while keeping track of operations needed to adjust numbers.\nShrink the window by moving left when the operation count exceeds k.\n- 3, Two Passes:\nFirst pass: Calculate frequency for numbers already in the list.\nSecond pass: Consider cases where the target number is not initially in the array.\n# Complexity\n- Time complexity:\nSorting takes O(nlogn), and the sliding window runs in O(n).\n- Space complexity: O(n)\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        memo = defaultdict(int)\n        max_frequency, left, right = 0, 0, 0\n\n        # find if the frequent number could be made max\n        for num in nums:\n    \n            while right < n and num + k >= nums[right] :\n                memo[nums[right]] += 1\n                right += 1\n            while left < n and num - k > nums[left]:\n                memo[nums[left]] -= 1\n                left += 1\n\n            current_max = min(right-left, numOperations + memo[num])\n            max_frequency = max(max_frequency, current_max)\n\n        left = 0\n        # in case the target is not in the list\n        for right in range(n):\n            while nums[left] + 2*k < nums[right]:\n                left += 1\n            max_frequency = max(max_frequency, min(right-left+1, numOperations))\n        return max_frequency\n```
['Array', 'Greedy', 'Sliding Window', 'Sorting', 'Python3']