Greedy Algorithms8 sections · 316 units
Open in Course

Problem - Minimum Increment to Make Array Unique

No duplicates

Given an array, in one move you can increment any element by 11. Find the minimum moves to make all elements unique. For [1,2,2][1,2,2], increment one 22 to 33. Answer is 11. For [3,2,1,2,1,7][3,2,1,2,1,7], answer is 66.

Think about what happens if you sort the array first. Duplicates become adjacent. Constraint: increments are unlimited, so every array has a solution. After sorting, duplicates cluster together, making it easy to detect violations. The final array will be a consecutive or near-consecutive sequence starting from the smallest element.