0

I'm on my third day in HackerRank doing the zigzag sequence and although my output is the same as the expected output, it keeps saying I got the wrong answer: Had the same problem with my mock test earlier and am extremely frustrated by this since I couldn't finish the test on time because of it. Has anyone experienced anything similar on HackerRank?

I'm also quite new to posting on stack overflow so if theres anything wrong or anything that could be better about my questioning please let me know.

my output:1 2 3 7 6 5 4 expected output: 1 2 3 7 6 5 4

My code is written below:

def findZigZagSequence(a, n):

a.sort()
mid = int((n + 1)/2) - 1
a[mid], a[n-1] = a[n-1], a[mid]

st = mid + 1 # 4ele = 5
ed = n - 2 #5ele = 6
while(st <= ed):
    a[st], a[ed] = a[ed], a[st]
    st = st + 1
    ed = ed - 1

for i in range (n):
    if i == n-1:
        print(a[i])
    else:
        print(a[i], end = ' ')
return

test_cases = int(input()) for cs in range (test_cases): n = int(input()) a = list(map(int, input().split())) findZigZagSequence(a, n)

niconico
  • 9
  • 2

0 Answers0