We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I am getting this output but still all my test cases are not able to pass for eg. n = 92 k = 14
My goes like this in python 3----
cases = int(input())
for i in range(cases):
n,k = map(int,input().split())
res = str()
arr =[]
for j in range(n+1):
if (j == 0):
arr.append(0)
else :
arr.append(j)
check = [0]
for m in range(1,len(arr)):
add = m + k
sub = m-k
if sub > 0 and sub not in check:
check.append(sub)
continue
elif add < n+1 :
check.append(add)
continue
for j in range(1,len(check)):
if abs(check[j]-j)==k :
res = res + str(check[j]) + " "
else :
res = str(-1)
break
print(res.rstrip())
Your help will be highly oblidged
Cookie support is required to access HackerRank
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 →
I am getting this output but still all my test cases are not able to pass for eg. n = 92 k = 14 My goes like this in python 3----
cases = int(input()) for i in range(cases): n,k = map(int,input().split()) res = str() arr =[] for j in range(n+1): if (j == 0): arr.append(0) else : arr.append(j) check = [0] for m in range(1,len(arr)): add = m + k sub = m-k if sub > 0 and sub not in check: check.append(sub) continue elif add < n+1 : check.append(add) continue for j in range(1,len(check)): if abs(check[j]-j)==k : res = res + str(check[j]) + " " else : res = str(-1) break print(res.rstrip())
Your help will be highly oblidged