You're given an integer array nums and an integer k. Your mission is to maximize the number of distinct elements in the array by strategically adjusting each element.
The Rule: For each element in the array, you can perform at most one operation - add any integer from the range [-k, k] to that element. This means you can decrease it by up to k, increase it by up to k, or leave it unchanged.
Goal: Return the maximum possible number of distinct elements after performing these operations optimally.
Example: If nums = [1, 2, 2, 3] and k = 1, you could transform it to [1, 1, 3, 3] (no change, decrease by 1, increase by 1, no change) to get 3 distinct elements. But with better strategy: [0, 2, 1, 3] gives you 4 distinct elements!
Input & Output
Constraints
- 1 โค nums.length โค 105
- 1 โค nums[i] โค 109
- 0 โค k โค 109
- Each element can be modified at most once