Tap here to switch tabs
Problem
Submissions

Problem: Maximum Number of Distinct Elements After Operations

med
30 min
Try to solve the Maximum Number of Distinct Elements After Operations problem.

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

med
30 min
Try to solve the Maximum Number of Distinct Elements After Operations problem.

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