Generate an N | Function to print the permutation of size N with absolute difference of adjacent elements in range [ 2 , 4 ] ; If N is less than 4 ; Check if N is even ; Traverse through odd integers ; Update the value of i ; Traverse through even integers ; Driver Code
function getPermutation ( N ) { if ( N <= 3 ) { document . write ( - 1 ) ; return ; } let i = N ; if ( N % 2 == 0 ) i -- ; while ( i >= 1 ) { document . write ( i + " " ) ; i -= 2 ; } document . write ( 4 + " " + 2 + " " ) ; i = 6 ; while ( i <= N ) { document . write ( i + " " ) ; i += 2 ; } } let N = 9 ; getPermutation ( N ) ;