• + 1 comment

    Python

    def absolutePermutation(n, k):

    if k !=0 and n% (2*k) !=0:
        return [-1]
    if k == 0:
        return list(range(1, n+1))
    return [(u + k if (u-1) % (2*k) + 1 <= k else u - k) for u in range(1, n+1)]