Tap here to switch tabs
Problem
Submissions

Problem: Minimum Number of Operations to Make Array Continuous

Minimum Number of Operations to Make Array Continuous asks for the fewest replacements needed to make an integer array contain unique values with a range of exactly its length minus one.

Statement

You are given an integer array nums. In one operation, you can replace any element in nums with any other integer.

The array nums is considered continuous if both of the following conditions are satisfied:

  • All elements in nums are unique.

  • The difference between the maximum element and the minimum element in nums equals nums.length −1- 1.

Return the minimum number of operations required to make nums continuous.

Constraints:

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

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

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Number of Operations to Make Array Continuous

Minimum Number of Operations to Make Array Continuous asks for the fewest replacements needed to make an integer array contain unique values with a range of exactly its length minus one.

Statement

You are given an integer array nums. In one operation, you can replace any element in nums with any other integer.

The array nums is considered continuous if both of the following conditions are satisfied:

  • All elements in nums are unique.

  • The difference between the maximum element and the minimum element in nums equals nums.length −1- 1.

Return the minimum number of operations required to make nums continuous.

Constraints:

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

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