Permutation of Array such that products of all adjacent elements are even | Function to print the required permutation ; push odd elements in ' odd ' and even elements in 'even ; Check if it possible to arrange the elements ; else print the permutation ; Print remaining odds are even . and even elements ; Driver Code
def printPermutation ( arr , n ) : NEW_LINE INDENT odd , even = [ ] , [ ] NEW_LINE DEDENT ' NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT if ( arr [ i ] % 2 == 0 ) : NEW_LINE INDENT even . append ( arr [ i ] ) NEW_LINE DEDENT else : NEW_LINE INDENT odd . append ( arr [ i ] ) NEW_LINE DEDENT DEDENT size_odd = len ( odd ) NEW_LINE size_even = len ( even ) NEW_LINE if ( size_odd > size_even + 1 ) : NEW_LINE INDENT print ( - 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT i , j = 0 , 0 NEW_LINE while ( i < size_odd and j < size_even ) : NEW_LINE INDENT print ( odd [ i ] , end = " ▁ " ) NEW_LINE i += 1 NEW_LINE print ( even [ j ] , end = " ▁ " ) NEW_LINE j += 1 NEW_LINE DEDENT DEDENT while ( i < size_odd ) : NEW_LINE INDENT print ( odd [ i ] , end = " ▁ " ) NEW_LINE i += 1 NEW_LINE DEDENT while ( j < size_even ) : NEW_LINE INDENT print ( even [ j ] , end = " ▁ " ) NEW_LINE j += 1 NEW_LINE DEDENT DEDENT arr = [ 6 , 7 , 9 , 8 , 10 , 11 ] NEW_LINE N = len ( arr ) NEW_LINE printPermutation ( arr , N ) NEW_LINE