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 prlet the permutation ; Print remaining odds are even . and even elements ; Driver Code
function printPermutation ( arr , n ) { let odd = [ ] ; let even = [ ] ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % 2 == 0 ) even . push ( arr [ i ] ) ; else odd . push ( arr [ i ] ) ; } let size_odd = odd . length ; let size_even = even . length ; if ( size_odd > size_even + 1 ) document . write ( " " ) ; else { let i = 0 ; let j = 0 ; while ( i < size_odd && j < size_even ) { document . write ( odd [ i ] + " " ) ; ++ i ; document . write ( even [ j ] + " " ) ; ++ j ; } while ( i < size_odd ) { document . write ( odd [ i ] + " " ) ; ++ i ; } while ( j < size_even ) { document . write ( even [ j ] + " " ) ; } } } let arr = [ 6 , 7 , 9 , 8 , 10 , 11 ] ; let N = arr . length ; printPermutation ( arr , N ) ;