Intuitive Interval Overlap Trick - O(nlogn) Sweep Line
IntuitionThink of each num as having a reach of [x - k, x + k] which can then be framed as an interval overlap problem to see how many intervals (points) overla
# Intuition
Think of each num as having a reach of [x - k, x + k] which can then be framed as an interval overlap problem to see how many intervals (points) overlap at a certain location.

# Approach
Convert each number into its corresponding interval with (x - k, 1) indicating the start of the interval, (x + k, -1) for the end of the interval.

-  (x, 0) to handle cases of turning other nums into an already existing number, in which case the total freq we have is $counts[num] + numOperations$ not just $numOperations$

# Complexity
- Time complexity:
$$O(nlogn)$$

- Space complexity:
$$O(n)$$

# Code
```python3 []
class Solution:
    def maxFrequency(self, nums: List[int], k: int, numOperations: int) -> int:
        # turn into intervals
        counts = Counter(nums)
        events = []
        for num in nums:
            events.append((num - k, 1))
            events.append((num, 0))
            events.append((num + k + 1, -1))

        events.sort()
        max_freq = freq = 0

        for num, delta in events:
            freq += delta
            max_freq = max(max_freq, min(numOperations + counts[num], freq))

        return max_freq
```
['Python3']