Tap here to switch tabs
Problem
Submissions

Problem: Maximum Number of Distinct Elements After Operations

Maximum Number of Distinct Elements After Operations lets you adjust each array value at most once within a range of k and return the greatest number of distinct values possible.

Statement

You are given an integer array nums and an integer k.

You are allowed to perform the following operation on each index at most once: replace nums[i] with any integer in the range [[nums[i] −k,- k, nums[i] +k]+ k].

Return the maximum possible number of distinct elements in nums after applying these operations.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤109\leq 10^9

  • 0≤0 \leq k ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Number of Distinct Elements After Operations

Maximum Number of Distinct Elements After Operations lets you adjust each array value at most once within a range of k and return the greatest number of distinct values possible.

Statement

You are given an integer array nums and an integer k.

You are allowed to perform the following operation on each index at most once: replace nums[i] with any integer in the range [[nums[i] −k,- k, nums[i] +k]+ k].

Return the maximum possible number of distinct elements in nums after applying these operations.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤109\leq 10^9

  • 0≤0 \leq k ≤109\leq 10^9