Making elements distinct in a sorted array by minimum increments | To find minimum sum of unique elements . ; While current element is same as previous or has become smaller than previous . ; Driver code
< ? php function minSum ( $ arr , $ n ) { $ sum = $ arr [ 0 ] ; for ( $ i = 1 ; $ i < $ n ; $ i ++ ) { if ( $ arr [ $ i ] == $ arr [ $ i - 1 ] ) { $ j = $ i ; while ( $ j < $ n && $ arr [ $ j ] <= $ arr [ $ j - 1 ] ) { $ arr [ $ j ] = $ arr [ $ j ] + 1 ; $ j ++ ; } } $ sum = $ sum + $ arr [ $ i ] ; } return $ sum ; } $ arr = array ( 2 , 2 , 3 , 5 , 6 ) ; $ n = sizeof ( $ arr ) ; echo minSum ( $ arr , $ n ) , " STRNEWLINE " ; ? >