Zig Zag Sequence

Sort by

recency

|

1050 Discussions

|

  • + 0 comments

    Misisng typescript template for findZigZagSequence.

  • + 0 comments

    findZigZagSequence starting code is missing for C++

  • + 0 comments

    My solution which used Python (PyPy3) failed. Same solution in C++ 14 passed.

  • + 1 comment

    Java 15, while an available language from the dropdown, seems to be missing the starting code. Seems like a big oversight that should be fixed.

  • + 2 comments

    I got my output equal to the expected and I only modified 3 lines of code. Still getting the test failing. Using Java 8.

        public static void findZigZagSequence(int [] a, int n){
            Arrays.sort(a);
            int mid = (n + 1)/2;
            int temp = a[--mid];
            a[mid] = a[n - 1];
            a[n - 1] = temp;
        
            int st = mid + 1;
            int ed = n - 2;
            while(st <= ed){
                temp = a[st];
                a[st] = a[ed];
                a[ed] = temp;
                st = st + 1;
                ed = ed - 1;
            }
            for(int i = 0; i < n; i++){
                if(i > 0) System.out.print(" ");
                System.out.print(a[i]);
            }
            System.out.println();
        }