Generate an N | Java program for tha above approach ; 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
import java . util . * ; class GFG { static void getPermutation ( int N ) { if ( N <= 3 ) { System . out . print ( - 1 ) ; return ; } int i = N ; if ( N % 2 == 0 ) i -- ; while ( i >= 1 ) { System . out . print ( i + " ▁ " ) ; i -= 2 ; } System . out . print ( 4 + " ▁ " + 2 + " ▁ " ) ; i = 6 ; while ( i <= N ) { System . out . print ( i + " ▁ " ) ; i += 2 ; } } public static void main ( String [ ] args ) { int N = 9 ; getPermutation ( N ) ; } }