njain794 / Mission-SDE

Curated List of topics and solutions of questions asked by Product Based Companies during their Coding round and interviews
1 stars 0 forks source link

c++ stl ghg #5

Open KIRA96855 opened 2 years ago

KIRA96855 commented 2 years ago

i need your help in gfg c++ stl contest 2 second question the pendulum swings how can i contact you

KIRA96855 commented 2 years ago

vector thePendulum(vectorv) {

sort(v.begin(), v.end()); int t,n,k=1; // int n=floor(v.size()/2); vectorc; if(v.size()%2==0) n=v.size(); else n=v.size()-1;

for(int i=0;i<n-1;i+=2){ t=i+1; if(k%2!=0) { c.insert(c.begin(),v[i]); c.insert(c.begin(),v[t]); //c.push_back(v[t]); //c.push_back(v[i]);

} else { c.push_back(v[i]); c.push_back(v[t]); } k++;

} if(v.size()%2!=0) { c.insert(c.begin(),v[n]); } return c;