Replace two consecutive equal values with one greater | python 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
from __future__ import print_function NEW_LINE def replace_elements ( arr , n ) : NEW_LINE INDENT pos = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT arr [ pos ] = arr [ i ] NEW_LINE pos = pos + 1 NEW_LINE while ( pos > 1 and arr [ pos - 2 ] == arr [ pos - 1 ] ) : NEW_LINE INDENT pos -= 1 NEW_LINE arr [ pos - 1 ] += 1 NEW_LINE DEDENT DEDENT for i in range ( 0 , pos ) : NEW_LINE INDENT print ( arr [ i ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT arr = [ 6 , 4 , 3 , 4 , 3 , 3 , 5 ] NEW_LINE n = len ( arr ) NEW_LINE replace_elements ( arr , n ) NEW_LINE