Back to course home
0% completed
Vote For New Content
Minimum Increment to Make Array Unique (medium)
Problem Statement
You are given an array of integers nums. In a single move, you can pick any index i, where 0 <= i < nums.length and add 1 to nums[i].
Return the minimum number of moves to make all elements in the nums unique.
Examples
Example 1
- Input: nums =
[4, 3, 2, 2, 1, 4] - Output:
5 - Explanation: We need
1move to increment the4at index 5 to5, and then4moves to increment the2at index 4 to6. So, we need total5moves.
Example 2
- Input: nums =
[5, 5, 5, 5, 5] - Output:
10
.....
.....
.....
Like the course? Get enrolled and start learning!
On this page