Practice Maximum Number of Distinct Elements After Operations
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Given nums and k, you may add an integer from -k through k to each element at most once. Return the maximum number of distinct values achievable.
Source: Maximum Number of Distinct Elements After Operations on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
nums = [1,2,2,3,3,4], k = 2
Output
6
# Example 2
Input
nums = [4,4,4,4], k = 1
Output
3
Constraints
1 <= nums.length <= 10^5
1 <= nums[i] <= 10^9
0 <= k <= 10^9
Related LeetCode Problems
Practice more problems similar to Maximum Number of Distinct Elements After Operations.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.