Max Frequency Element Window
You are given an integer array nums and an integer k. In one operation, you may choose any element and increment it by 1.
Your task is to find the maximum possible frequency of any value in the array after performing at most k operations.
You may choose which elements to increment and which target value to convert them to, but each increment costs 1 operation.
Examples
Input: [1,2,3]
Output: 3
Input: [1,2,3]
Output: 3
Hints
If you sort the array, the elements you transform into a common target will always form a contiguous segment. Why would a gap make it wasteful?
When a segment's cost exceeds `k`, you can drop the leftmost element instead of resetting. Think about how the cost changes as the window slides.
For a window of identical target values, the number of operations needed is `(window_size × target) - (sum of elements in window)`. Express the target in terms of the window's rightmost element.
Max Frequency Element Window
You are given an integer array `nums` and an integer `k`. In one operation, you may choose any element and increment it by `1`.