Zig Zag Sequence

  • + 0 comments

    `What is the problem?

    //C++

    void findZigZagSequence(vector < int > a, int n){

        sort(a.begin(), a.end());

        int mid = (n + 1)/2;

        int st = mid - 1;

        int ed = n - 1;

        while(st <= ed){

            swap(a[st], a[ed]);

            st = st + 1;

            ed = ed - 1;

        }

        for(int i = 0; i < n; i++){

            if(i > 0) cout << " ";

            cout << a[i];

        }

        cout << endl;

    } `

    running failed: 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