DP + Sliding window [EXPLAINED]
IntuitionWe need to maximize the frequency of the same number in the array after performing a series of operations. Each operation allows us to add a number in
# Intuition
We need to maximize the frequency of the same number in the array after performing a series of operations. Each operation allows us to add a number in the range [-k, k] to any element. By sorting the array first, it becomes easier to find consecutive numbers that can be transformed into each other with minimal changes.

# Approach
I first sort the array, then iterate through each number, calculating its frequency range (how many numbers in the array can be transformed into it within k operations). For each number, I calculate the maximum achievable frequency by considering both its direct transformations and those within a 2k range, updating the result as I go.

# Complexity
- Time complexity:
O(n log n), where n is the length of the array. The binary search operations for each element run in O(log n) time, so the overall complexity is O(n log n).

- Space complexity:
O(1) extra space since we're only using a few variables to store intermediate results and don't need any additional data structures apart from the input array.

# Code
```kotlin []
class Solution {
    private fun binarySearch(nums: IntArray, target: Int, isLast: Boolean): Int {
        var left = 0
        var right = nums.size - 1
        
        while (left <= right) {
            val mid = (left + right) / 2
            when {
                nums[mid] == target -> if (isLast) left = mid + 1 else right = mid - 1
                nums[mid] > target -> right = mid - 1
                else -> left = mid + 1
            }
        }
        
        return if (isLast) left - 1 else right + 1
    }
    
    fun maxFrequency(nums: IntArray, k: Int, numOperations: Int): Int {
        nums.sort()
        var maxFreq = 0
        
        for (i in nums.indices) {
            if (i == 0 || nums[i] != nums[i - 1]) {
                val curLastOcc = binarySearch(nums, nums[i], true)
                val curFirstOcc = binarySearch(nums, nums[i], false)
                val freqAvail = binarySearch(nums, nums[i] + k, true) - curLastOcc + curFirstOcc - binarySearch(nums, nums[i] - k, false)
                
                maxFreq = maxOf(maxFreq, curLastOcc - curFirstOcc + 1 + minOf(freqAvail, numOperations))
                maxFreq = maxOf(maxFreq, minOf(binarySearch(nums, nums[i] + 2 * k, true) - curFirstOcc + 1, numOperations))
            }
        }
        
        return maxFreq
    }
}

```
['Array', 'Hash Table', 'Math', 'Binary Search', 'Dynamic Programming', 'Ordered Map', 'Sliding Window', 'Simulation', 'Hash Function', 'Kotlin']