Zig Zag Sequence

Sort by

recency

|

940 Discussions

|

  • + 0 comments

    My output matches the expected output, but I'm still getting a "Wrong Answer" message (yes, I editted only 3 lines of code). Seems like this is happening to a lot of other people too, judging from the comments. Something about this problem is broken.

    EDIT: a possible fix is to reset the code, then reapply your changes (should be simple if you think you found a solution). My submission was accepted after resetting. So maybe the compiler "remembers" changes made to other lines of code, even if those changes are later undone.

  • + 0 comments

    Doing challenge in C# here.

    FOUR CRITICAL issues with this question:

    1) The question states "the task is to debug the existing code to ..."

    -> There is no existing code (apart from "Main" function header) in C#.

    all other challegnes so far have at least the boilerplate code to read the input from STDIN and output result.

    Seems like an overlook / missing work from the maintainer.

    2) Question states "Note: You can modify at most three lines in the given code. You cannot add or remove lines of code. "

    I don't see how this is possible to add 3 lines of code from virtually no code to solve this (see previous remark), except by stretching the definition of "line of code" and put every statement on the same line separated by ";" .

    3) the examples in description are ambiguous :

    "You need to find the lexicographically smallest zig zag sequence of the given array.".

    Just below this, an example shows: """ Example. a= [2, 3, 5, 1, 4]

    Now if we permute the array as [1, 4, 5, 3, 2], the result is a zig zag sequence. """

    But a smaller lexicographic zigzag sequence would be [1, 2, 5, 4, 3] ... Why is this example shown if this is not the expected output ?

    4) The exercise is definitely broken. I have the exact same answer as expected output but the run test sohws "Wrong answer": Compiler Message

    Wrong Answer

    Input (stdin)

    1
    
    7
    
    1 2 3 4 5 6 7
    

    Your Output (stdout)

    1 2 3 7 6 5 4
    

    Expected Output

    1 2 3 7 6 5 4
    
    
    
    :(
     :( 
     :(
    
  • + 1 comment

    I see the same output and it still says wrong answer. I think there is a bug here.

    This is my code, try it yourself.

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

    st = mid + 1
    ed = n - 2
    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)

  • + 0 comments

    Check the indexes for mid, st and ed.

  • + 0 comments

    Check the indexes for mid, st and ed.