Leetcode 982 Solution

This article provides solution to leetcode question 982 (minimum-increment-to-make-array-unique)

https://leetcode.com/problems/minimum-increment-to-make-array-unique

Solution

class Solution:
    def minIncrementForUnique(self, nums: List[int]) -> int:
        need = 0
        ans = 0

        for num in sorted(nums):
            ans += max(need - num, 0)
            need = max(need, num) + 1
        return ans