#945
Minimum Increment to Make Array Unique
specialist · 700 · lc medium +30 · verified · 60.6% accepted · 2,775 likes · top 59%
Description
Given integer array nums, you can pick any element and increment it by 1. Return the minimum number of such single-unit increments needed so that all elements of nums are distinct.
Example 1:
Input: nums = [1,2,2]
Output: 1
Explanation: After 1 move, the array could be [1, 2, 3].
Example 2:
Input: nums = [3,2,1,2,1,7]
Output: 6
Explanation: After 6 moves, the array could be [3, 4, 1, 2, 5, 7].
It can be shown that it is impossible for the array to have all unique values with 5 or less moves.
Code
1
2
3