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 17%
Steffan
voytxt
XenThe
helbling
#2
46 c.
Top 22%
tree
#3
48 c.
Top 26%
Lv0Sys
#4
53 c.
Top 35%
lydxn
sean
#5
54 c.
Top 43%
oskar
Ryan
#6
59 c.
Top 48%
Shanethegamer
#7
66 c.
Top 52%
Alex
#8
72 c.
Top 57%
scpchicken
#9
78 c.
Top 61%
Thomasdcrt
#10
79 c.
Top 65%
Natanaelel
#11
80 c.
Top 70%
maximec-indy
#12
83 c.
Top 74%
KrausRaus
#13
95 c.
Top 78%
Pascal
#14
114 c.
Top 83%
SephQ
#15
181 c.
Top 87%
ComputerKWasTaken
#16
297 c.
Top 91%
Venkata
#17
326 c.
Top 96%
Ahmad
#18
447 c.
Top 100%
Abdelrahman