🎯 Sliding Window (I believe we suffered the same)
\n## Intuition:\nThe goal is to maximize the frequency of a number in an array by incrementing elements to match other values, within a given operation limit. S
\n## Intuition:\nThe goal is to maximize the frequency of a number in an array by incrementing elements to match other values, within a given operation limit. Sorting the array and using a sliding window approach helps us efficiently find the maximum frequency we can achieve under these constraints.\n\n## Approach:\n1. **Sort the Array**:\n   - Sorting allows us to work with contiguous elements in a window, making it easier to calculate the required operations to equalize elements within this window.\n\n2. **Sliding Window with Two Pointers**:\n   - Use two pointers (`left` and `right`) to define a window of elements.\n   - For each `mid` element in this window, calculate the maximum frequency achievable with the allowed number of operations.\n   - Adjust the `left` pointer when the difference between `nums[mid]` and `nums[left]` exceeds `k`.\n\n3. **Track Maximum Frequency**:\n   - For each valid window (where the difference is within `k`), update `maxFrequency` if the frequency achieved is higher.\n\n## Complexity:\n- **Time complexity**:  \n  $$O(n \\log n)$$ \u2014 Sorting the array takes `O(n log n)`, and the sliding window process is `O(n)`.\n\n- **Space complexity**:  \n  $$O(1)$$ \u2014 Uses only a few variables for counting and sliding window manipulation.\n\n# Code:\n```csharp []\npublic class Solution {\n    public int MaxFrequency(int[] nums, int k, int numOperations) {\n        var n = nums.Length;\n        if (n == 1)\n            return 1;\n        \n        Array.Sort(nums);\n        \n        var counts = new Dictionary<int, int>();\n        foreach (var num in nums)\n        {\n            if (!counts.ContainsKey(num))\n                counts[num] = 0;\n\n            counts[num]++;\n        }\n\n        int left = 0, right = 1;\n        var maxFrequency = 1;\n\n        for (int mid = 1; mid < n; mid++)\n        {\n            while (nums[mid] - nums[left] > k)\n                left++;\n\n            while (right+1 < n && nums[right+1] - nums[mid] <= k)\n                right++;\n\n            var midCount = counts[nums[mid]];\n            var windowSize = right - left + 1 - midCount;\n            var operatedCount = Math.Min(windowSize, numOperations);\n            maxFrequency = Math.Max(maxFrequency, operatedCount + midCount);\n        }\n\n        left = 0;\n        for (right = maxFrequency-1; right < n; right++)\n        {\n            var mid = (nums[right] + nums[left]) / 2;\n\n            while (mid - nums[left] > k || nums[right] - mid > k)\n            {\n                left++;\n                mid = (nums[right] + nums[left]) / 2;\n            }\n\n            var windowSize = right - left + 1;\n            var operatedCount = Math.Min(windowSize, numOperations);\n            maxFrequency = Math.Max(maxFrequency, operatedCount);\n        }\n    \n        return maxFrequency;\n    }\n}\n\n\n//\n// \n//     num operations = 3\n//      k = 100\n//                    1 2 3 4   5  6 20 20\n//                    4 5 6 20 20 20    \n//\n//                    1 2 3 104 105 106 120 120\n//                    3 3 3 120 120 120\n// \n//      numoper = 100\n//      k = 12\n//                    1, 2, 3, 100, 1000, 100, 1000, 100, 1000, 100, 1000, 100, 1000, 100, 1000, 100, 1000, 100, 1000, 100, 1000\n//                      \n\n```
['Hash Table', 'Sliding Window', 'C#']