Trains the technique from
LeetCode 3434Maximum Frequency After Subarray OperationThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
Dial readings are given as nums.
Choose exactly one contiguous stretch of the readings and add the same whole number to every reading in it. That number may be negative, and it may be zero.
Return the greatest number of readings that can end up equal to k.
Example 1
Three readings already show 7. Adding four to the stretch covering positions 0 to 2 turns two threes into sevens while pushing the single 7 inside it off, for a net gain of one, giving four in all.
Example 2
Adding one to the whole list turns every reading into 2.
Example 3
Every reading is the same, so one shift moves as many of them onto 3 as the stretch covers, and covering all four is best.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def max_frequency(nums: list[int], k: int) -> int:public int maxFrequency(int[] nums, int k)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.