Skip to main content
Back to problems
Leetcode
Medium
Arrays
Hash Maps
Greedy
Amazon
Minimum Number of Operations To Make Elements in Array Distinct

Find the minimum number of operations needed to make all array elements distinct, using the operation allowed by the problem.

Acceptance 0%
Problem Statement

You are given an integer array. In one operation, you may modify the array according to the problem's allowed rule so that duplicates can eventually be removed. Your goal is to determine the minimum number of operations required so that every value in the array becomes distinct.

Think in terms of how many repeated elements must be resolved and how the operation affects the array globally or locally. Return the smallest number of operations needed to make the array contain no duplicate values.

Input Format

  • An integer array nums.
  • The exact operation is defined by the problem statement on the platform.

Note: This is a practice-oriented rephrasing; the implementation details should follow the platform's original operation rule.

Output Format

  • Return an integer: the minimum number of operations needed to make all elements distinct.

Constraints

  • The array may contain duplicate values.
  • The answer should be the minimum possible number of operations under the allowed operation rule.
  • Use the platform's original constraints for exact limits.
Examples
Sample cases returned by the problem API.

Example 1

Input

nums = [1,2,3,4]

Output

0

Explanation

All elements are already distinct, so no operations are needed.

Example 2

Input

nums = [1,2,2,3,3,3]

Output

2

Explanation

The repeated values can be resolved in the minimum number of allowed operations, leaving all elements distinct.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.