-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAbsolute Permutation.py
More file actions
47 lines (33 loc) · 895 Bytes
/
Absolute Permutation.py
File metadata and controls
47 lines (33 loc) · 895 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
'''
Problem Statement: https://www.hackerrank.com/challenges/absolute-permutation/problem
@Coded by TSG, 2020
'''
import math
import os
import random
import re
import sys
# Complete the absolutePermutation function below.
def absolutePermutation(n, k):
out = []
switch = k
if k == 0:
return [x for x in range(1, n+1)]
if n % (2*k) != 0:
return [-1]
for pos in range(1, n + 1):
out.append(pos + switch)
if pos % k == 0:
switch *= -1
return out
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input())
for t_itr in range(t):
nk = input().split()
n = int(nk[0])
k = int(nk[1])
result = absolutePermutation(n, k)
fptr.write(' '.join(map(str, result)))
fptr.write('\n')
fptr.close()