You are viewing a single comment's thread. Return to all comments →
Here are my 3 changes in C++, should not be too difficult for other languages too
void findZigZagSequence(vector < int > a, int n) { sort(a.begin(), a.end()); int mid = n/2; // 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 } .... }
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 →
Here are my 3 changes in C++, should not be too difficult for other languages too