Reading time: 35 minutes | Coding time: 10 minutes
We are given a sorted array (if not, then sort it using any sorting algorithm or built in functions) which might have duplicate elements, our task is to find the minimum number of increment (by 1) operations needed to make the elements of an array unique.
Example : Consider a sorted array - x [1,2,4,4,4,5].
i=0 : x[i] = 1 (Unique)
i=1 : x[i] = 2 (Unique)
i=2 : x[i] = 4 (Unique)
i=3 : x[i] = 4 (increment once to get 5) => res = 1
i=4 : x[i] = 4...
Published on June 22, 2020 11:47