title: I need to find permutation of natural numbers such that abs(pos[i]-i==k) where k is constant for all natural nos
body: <pre><code>if n=4
  first natural numbers are [1,2,3,4]
  we could rearrange to [3,4,1,2]
  so that pos[i]-i==2 for every natural no
  </code></pre>
  
  <p><a href="https://www.hackerrank.com/challenges/absolute-permutation/problem" rel="nofollow noreferrer">https://www.hackerrank.com/challenges/absolute-permutation/problem</a></p>
  
  <p>t are the test cases    </p>
  
  <pre><code>def absolutePermutation(n, k):
          for i in range(t):
              pos=[]
              for j in range(1,n+1):
                  if(j+k&lt;=n):
                      pos.append(j+k)
                  elif(j==k):
                      pos.append(j)
                  else:
                      pos.append(j-k)
          if all(abs(pos[x]-(x+1))==k for x in range(len(pos))):
              return pos
          else:
              return [-1]
  </code></pre>
  
  <p>for 10 5</p>
  
  <p>output</p>
  
  <blockquote>
    <p>6 7 8 9 10 1 2 3 4 5</p>
  </blockquote>
  
  <p>for 10 1 </p>
  
  <p>i am getting wrong answer
  expected output</p>
  
  <blockquote>
    <p>2 1 4 3 6 5 8 7 10 9</p>
  </blockquote>