Help me in solving DIFFMED problem

My issue

my code is correct by when i submit it is showing wrong please debug the test cases

My code

# cook your dish here
for i in range(int(input())):
    n = int(input())
    mylist = []
    first = 1
    last = n
    for i in range(n//2):
        mylist.append(first)
        mylist.append(last)
        first+=1
        last-=1
    if n%2 !=0:
        print(first,*mylist)
    else:
        temp = mylist[-1]
        mylist[-1] = mylist[-2]
        mylist[-2] = temp
        print(*mylist)

Problem Link: Different Medians Practice Coding Problem

I’m not sure about the logic behind on how you determinate the median, but this should work:

def innum():
    return int(input())

for T in range(innum()):
    
    N = innum()
    
    # If N is even, I'll do this (assuming N = 6)
    # 6 1 5 2 4 3
    # If N is odd, I'll do this (assuming N = 7)
    # 6 1 5 2 4 3 7
    
    
    if N % 2 == 0:
        n = N
    else:
        n = N - 1
    
    nums = []
    for i in range(n//2):
        nums.append(n-i)
        nums.append(1+i)
    
    if N % 2 == 1:
        nums.append(N)
    
    print(*nums)
1 Like

thank’s bro