Zig Zag Sequence

Sort by

recency

|

70 Discussions

|

  • + 0 comments

    C++20 Has no code to debug

  • + 0 comments

    Hi,

    somehow the answer is not accepted even if the output looks same to me.

    I copied this Solution in Python: https://github.com/JayantGoel001/HackerRank/blob/master/Zig%20Zag%20Sequence.py

    Someone made the same experience?

  • + 0 comments

    for Typescript and Javascript the code is initially broken. I see, for instance, in Python there is a code which you could fix, but not tor TS and JS

  • + 0 comments

    Am I misunderstanding 'lexicographically smallest'?

    The example gives [1, 4, 5, 3, 2] as the answer, but the sequence [1, 2, 5, 4, 3] is lexicographically smaller. Both are 'zig zag sequences' as defined by the problem

  • + 1 comment

    output is correct, but fail all testcase???

    def findZigZagSequence(a, n):
        a.sort()
        mid = int((n + 1)/2) - 1 # 1st Edit: added -1 for the correct mid
        a[mid], a[n-1] = a[n-1], a[mid]
    
        st = mid + 1
        ed = n - 2 # 2nd Edit: change -1 to -2 for the correct initial ed value
        while(st <= ed):
            a[st], a[ed] = a[ed], a[st]
            st = st + 1
            ed = ed - 1 #3rd Edit: changed +1 to -1 for the correct swap.
    
        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)
    
    # Enter your code here. Read input from STDIN. Print output to STDOUT
    

    `