Sort by

recency

|

206 Discussions

|

  • + 0 comments
    if __name__ == '__main__':
        t = int(input().strip())
        for i in range(t):
            first_multiple_input = input().rstrip().split()
            n = int(first_multiple_input[0])
            k = int(first_multiple_input[1])
            p=[]
            if n%2==0:
                for i in range(n//2):
                    p.append(n-1-i)
                    p.append(i)
            else:
                for i in range(n//2+1):
                    if i==n//2:
                        p.append(n-1-i)
                        break
                    p.append(n-1-i)
                    p.append(i)
            print(p.index(k))
    
  • + 0 comments

    use std::cmp::min;

    fn reverse_game(n: i32, k: i32) -> i32 { // value at index 0 is n-1, index 2 is n-2, index 4 is n-3 ... // value at index 1 is 0, index 2 is 2, index 4 is 3 ... min((2*k)+1, 2*(n-k-1)) }

  • + 0 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))

  • + 0 comments
    Quick edit. I figured it out. Maybe this will help if someone tries this approach. I made the mistake of storing these values as a concatenated string. So it works... until you pass the single digits... Because when it looks for the index of a given K, this K will catch the first character matches.

    Question for you all

    Any input would be greatly appreciated. I am wondering why I am getting this answer wrong. I identified the patterns and found that even positions decrease as the series goes on and the odd positions decrease. I built a loop to make make a new string that stores the reversing of the numbers. Then I only look for the index of the string containing k.

    When I text it with the example zero it works. I have also done it with other manual examples and it seems to work fine. Not sure why it marks every other example as incorrect ` if name == 'main': t = int(input().strip()) for _ in range(t): # Loop t times first_multiple_input = input().rstrip().split()

        n = int(first_multiple_input[0])
    
        k = int(first_multiple_input[1])
        result_string = ""
        high = n - 1
        low = 0
        for i in range(n):
            if i % 2 == 0:  # Even index: use the high value
                result_string += str(high)
                high -= 1
            else:  # Odd index: use the low value
                result_string += str(low)
                low += 1
    
        index = result_string.index(str(k))  # Find the index of K as a string
        print(index)    
    

  • + 1 comment

    Is this broken? The Solution code only brings in the first test case. The T variable tells me there should be 2 cases but only one value for N and K come in. Is there something I need to do to get all the test cases?