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 15%
helbling
Steffan
voytxt
#2
46 c.
Top 20%
tree
#3
53 c.
Top 30%
sean
lydxn
#4
54 c.
Top 40%
oskar
Ryan
#5
59 c.
Top 45%
Shanethegamer
#6
66 c.
Top 50%
Alex
#7
72 c.
Top 55%
scpchicken
#8
78 c.
Top 60%
Thomasdcrt
#9
79 c.
Top 65%
Natanaelel
#10
80 c.
Top 70%
maximec-indy
#11
83 c.
Top 75%
KrausRaus
#12
95 c.
Top 80%
Pascal
#13
114 c.
Top 85%
SephQ
#14
181 c.
Top 90%
ComputerKWasTaken
#15
326 c.
Top 95%
Ahmad
#16
447 c.
Top 100%
Abdelrahman