Fewest Increments to Distinct Values
In one move you add 1 to any single item of nums. Return the fewest moves that make every value in nums different from every other value. Items are never decreased. An empty list or a list with one item needs 0 moves.
Example 1
nums [1,2,2]
returns 1
Raise one of the 2s to 3: one move.
Example 2
nums [3,2,1,2,1,7]
returns 6
Sorted, the values are 1, 1, 2, 2, 3, 7. Turning them into 1, 2, 3, 4, 5, 7 costs 0 + 1 + 1 + 2 + 2 + 0 = 6 moves, and nothing cheaper works.
Constraints
0 <= len(nums) <= 100-1000 <= nums[i] <= 1000
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Greedy problems
- Fewest Jumps to the EndMedium
- Fewest PlatformsMedium
- Fewest Routers for a CorridorMedium
- Jump GameMedium
- Largest Tidy Number BelowMedium
- Make Letter Counts DistinctMedium
- Most Fairs VisitedMedium
- Shortest Schedule With CooldownMedium