Generate an N | Function to print 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
def getPermutation ( N ) : NEW_LINE INDENT if ( N <= 3 ) : NEW_LINE INDENT print ( - 1 ) NEW_LINE return NEW_LINE DEDENT i = N NEW_LINE if ( N % 2 == 0 ) : NEW_LINE INDENT i -= 1 NEW_LINE DEDENT while ( i >= 1 ) : NEW_LINE INDENT print ( i , end = " ▁ " ) NEW_LINE i -= 2 NEW_LINE DEDENT print ( 4 , 2 , end = " ▁ " ) NEW_LINE i = 6 NEW_LINE while ( i <= N ) : NEW_LINE INDENT print ( i , end = " ▁ " ) NEW_LINE i += 2 NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 9 NEW_LINE getPermutation ( N ) NEW_LINE DEDENT