Simple C++ 4 liner solution


#1

vector<int> Solution::wave(vector<int> &A) { int i,j; sort(A.begin(),A.end()); for(i=0;i<A.size()-1;i+=2) { cout<<A[i+1]<<" "<<A[i]<<" "; } if(A.size()%2) cout<<A[A.size()-1]<<" "; return {}; }


#2

Please note that this solution is not linear time, as you are sorting the array which takes nlogn time.


#3

bro read the heading again:joy::joy::joy:.