You're given an array nums of length n and a target value k. Your goal is to maximize the frequency of value k in the array by performing exactly one strategic operation.
The Operation: Select any subarray nums[i..j] (where 0 ≤ i ≤ j ≤ n-1) and add the same integer x to all elements in that subarray. You can choose any value for x (positive, negative, or zero).
Think of it as a puzzle: You have one chance to "adjust" a contiguous portion of your array. How do you use this power to create as many instances of your target value k as possible?
Example: If nums = [1, 2, 3] and k = 5, you could select subarray [2, 3] and add 3 to get [1, 5, 6], giving you 1 occurrence of k = 5. But is this optimal?
Input & Output
Constraints
- 1 ≤ n ≤ 105
- -109 ≤ nums[i] ≤ 109
- -109 ≤ k ≤ 109
- You must perform exactly one operation