You are viewing a single comment's thread. Return to all comments →
c++
vector<int> absolutePermutation(int n, int k) { vector<int> permuted(n,0); vector<bool> ussage(n,false); for (int i = 1; i<=n; i++){ if(i-k>0 && ussage[i-k-1]==false){ permuted[i-k-1] = i; ussage[i-k-1] = true; }else if(i+k<=n && ussage[i+k-1]==false){ permuted[i+k-1] = i; ussage[i+k-1] = true; }else{ return {-1}; } } return permuted; }
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 →
c++