Minimum Unique Array Sum

Given an array of integers, increment any duplicate elements until all elements are unique.

Medium1/4/2024

Problem statement

Given an array of integers, increment any duplicate elements until all elements are unique. The task is to minimize the sum of the array after making all elements unique.

Example:

// With the input
[7, 2, 1, 2, 4, 3] 

// Increment a 2 to get 
[7, 2, 1, 3, 4, 3]
// Increment a 3 to get 
[7, 2, 1, 3, 4, 4]
// Increment a 4 to get 
[7, 2, 1, 3, 4, 5]
// every element is now unique
// => sum : 22

Problem leaderboard

#
Size
%
Users
#1
43 c.
Top 7%
Steffan
#2
46 c.
Top 14%
tree
#3
53 c.
Top 36%
lydxn
voytxt
sean
#4
54 c.
Top 43%
oskar
#5
59 c.
Top 50%
Shanethegamer
#6
72 c.
Top 57%
scpchicken
#7
78 c.
Top 64%
Thomasdcrt
#8
79 c.
Top 71%
Natanaelel
#9
80 c.
Top 79%
maximec-indy
#10
83 c.
Top 86%
KrausRaus
#11
95 c.
Top 93%
Pascal
#12
181 c.
Top 100%
ComputerKWasTaken