Permutation of Array such that products of all adjacent elements are even | C # program to permutation of array such that product of all adjacent elements is 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
using System ; using System . Collections . Generic ; class GFG { static void printPermutation ( int [ ] arr , int n ) { List < int > odd = new List < int > ( ) ; List < int > even = new List < int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % 2 == 0 ) even . Add ( arr [ i ] ) ; else odd . Add ( arr [ i ] ) ; } int size_odd = odd . Count ; int size_even = even . Count ; if ( size_odd > size_even + 1 ) Console . WriteLine ( " - 1" ) ; else { int i = 0 ; int j = 0 ; while ( i < size_odd && j < size_even ) { Console . Write ( odd [ i ] + " ▁ " ) ; ++ i ; Console . Write ( even [ j ] + " ▁ " ) ; ++ j ; } while ( i < size_odd ) { Console . Write ( odd [ i ] + " ▁ " ) ; ++ i ; } while ( j < size_even ) { Console . Write ( even [ j ] + " ▁ " ) ; } } } public static void Main ( String [ ] args ) { int [ ] arr = { 6 , 7 , 9 , 8 , 10 , 11 } ; int N = arr . Length ; printPermutation ( arr , N ) ; } }