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.
from collections import deque # makes everything easy
if name == 'main':
t = int(input().strip())
for _ in range(t):
first_multiple_input = input().rstrip().split()
n = int(first_multiple_input[0])
k = int(first_multiple_input[1])
d=deque([i for i in range(n)])
l=[]
while len(d)>1:
l.append(d.pop())
l.append(d.popleft())
if len(d)==1:
l.append(d.pop())
print(l.index(k))
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Reverse Game
You are viewing a single comment's thread. Return to all comments →
from collections import deque # makes everything easy
if name == 'main': t = int(input().strip()) for _ in range(t): first_multiple_input = input().rstrip().split() n = int(first_multiple_input[0]) k = int(first_multiple_input[1]) d=deque([i for i in range(n)]) l=[] while len(d)>1: l.append(d.pop()) l.append(d.popleft()) if len(d)==1: l.append(d.pop()) print(l.index(k))