Replace two consecutive equal values with one greater | C # program to replace two elements with equal values with one greater . ; Function to replace consecutive equal elements ; Index in result ; to print new array ; Driver code
using System ; class GFG { static void replace_elements ( int [ ] arr , int n ) { int pos = 0 ; for ( int i = 0 ; i < n ; i ++ ) { arr [ pos ++ ] = arr [ i ] ; while ( pos > 1 && arr [ pos - 2 ] == arr [ pos - 1 ] ) { pos -- ; arr [ pos - 1 ] ++ ; } } for ( int i = 0 ; i < pos ; i ++ ) Console . Write ( arr [ i ] + " ▁ " ) ; } static void Main ( ) { int [ ] arr = { 6 , 4 , 3 , 4 , 3 , 3 , 5 } ; int n = arr . Length ; replace_elements ( arr , n ) ; } }