We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
make three changes in the given code, to get sample test cases pass.
modify your code to get debug exaclty...
void findZigZagSequence(vector < int > a, int n){
sort(a.begin(), a.end());
int mid = (n + 1)/2-1; //1st change
swap(a[mid], a[n-1]);
int st = mid + 1;
int ed = n - 2; //2nd change
while(st <= ed){
swap(a[st], a[ed]);
st = st + 1;
ed = ed - 1; //3rd change
}
for(int i = 0; i < n; i++){
if(i > 0) cout << " ";
cout << a[i];
}
cout << endl;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Zig Zag Sequence
You are viewing a single comment's thread. Return to all comments →
in C++
make three changes in the given code, to get sample test cases pass. modify your code to get debug exaclty...
void findZigZagSequence(vector < int > a, int n){ sort(a.begin(), a.end()); int mid = (n + 1)/2-1; //1st change swap(a[mid], a[n-1]);
}