You are viewing a single comment's thread. Return to all comments →
Here is my code
static int[] absolutePermutation(int n, int k) { int a[] = new int[n]; for(int i=0;i<n;i++) a[i] = i+1; if(k==0) return a; else if(n%(2*k)==0) { int x=1,y=1+k; int t = 0,flag=1; for(int i=0;i<k;i++) { a[i] = y; y++; } for(int i=k;i<2*k;i++) { a[i] = x; x++; } y+=k; if(n==2*k) return a; for(int i=2*k;i<n;i++) { if(flag == 1) { a[i] = y; } else { a[i] = x; } x++; y++; t++; if(t%k == 0) { if(flag==1) flag=-1; else flag =1; } } return a; } else { int b[] = new int[1]; b[0] = -1; return b; } }
Seems like cookies are disabled on this browser, please enable them to open this website
Absolute Permutation
You are viewing a single comment's thread. Return to all comments →
Here is my code