> ## Content Index
> Fetch the complete content index at: https://andybase.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# 945 Minimum Increment to Make Array Unique
- URL: https://andybase.com/945-minimum-increment-to-make-array-unique/
- Published: 2018-11-26T19:00:50.000Z
- Updated: 2018-11-26T19:00:50.000Z
- Author: andy
- Tags: leetcode, contest, #Migrated-1784083136856, #wp, #wp-post, #Import 2026-07-15 02:38

Link [Minimum Increment to Make Array Unique](https://leetcode.com/problems/minimum-increment-to-make-array-unique/?ref=andybase.com)

## Thought

Firstly, I try to enumerate all existing number, and I got TLE :(. Then I realized I could sort the origin array and maintain a upper boundary, for any number, if it smaller than upper boundary, means I can only move it to upper boundary + 1 and count the moves. Otherwise, set the upper boundary to that number and keep going. 

## Code

```
class Solution(object):
    def minIncrementForUnique(self, A):
        """
        :type A: List[int]
        :rtype: int
        """
        if not A:
            return 0
        p = dict()
        A.sort()
        cnt = 0
        upper = A[0]
        for i in A[1:]:
            if i <= upper:
                upper +=1
                cnt += upper - i
            else:
                upper = i 
        return cnt
```

## Runtime

Time: O(nlogn)  
Space: O(1)