• + 1 comment
    #include <bits/stdc++.h>
    using namespace std;
    
    void findZigZagSequence(vector <long int > a,long int n){
        sort(a.begin(), a.end());
        long int mid = (n + 1)/2;
        long int st = mid - 1;
        long int ed = n - 1;
        while(st <= ed){
            swap(a[st], a[ed]);
            st = st + 1;
            ed = ed - 1;
        }
        for(long int i = 0; i < n; i++){
            if(i > 0) cout << " ";
            cout << a[i];
        }
        cout << endl;
    }
    
    int main()
    {
        long int n, x;
        long int test_cases;
        cin >> test_cases;
    
        for(long int cs = 1; cs <= test_cases; cs++){
            cin >> n;
            vector <long int > a;
            for(long int i = 0; i < n; i++){
                cin >> x;
                a.push_back(x);
            }
            findZigZagSequence(a, n);
        }
        return 0;
    }
    

    My code is giving the exact same output which is shown in sample testcase but it is still showing me wrong answer. Can you tell me what is happening here?