Remove elements to make array sorted | Function to sort the array by removing misplaced elements ; l stores the index ; Print the sorted array ; Driver code
def removeElements ( arr , n ) : NEW_LINE INDENT l = 1 NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT if ( arr [ l - 1 ] <= arr [ i ] ) : NEW_LINE INDENT arr [ l ] = arr [ i ] NEW_LINE l += 1 NEW_LINE DEDENT DEDENT for i in range ( l ) : NEW_LINE INDENT print ( arr [ i ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 10 , 12 , 9 , 10 , 2 , 13 , 14 ] NEW_LINE n = len ( arr ) NEW_LINE removeElements ( arr , n ) NEW_LINE DEDENT