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.
#include<cmath>#include<cstdio>#include<vector>#include<iostream>#include<algorithm>usingnamespacestd;intmain(){/* Enter your code here. Read input from STDIN. Print output to STDOUT */intn;cin>>n;// Read the size of the vectorvector<int>v(n);// Declare a vector of size nfor(inti=0;i<n;i++){cin>>v[i];// Read the elements of the vector}intq1;cin>>q1;// Read the index to erasev.erase(v.begin()+q1-1);// Erase the element at index q1intq2,q3;cin>>q2>>q3;// Read the range [q2, q3) to erasev.erase(v.begin()+q2-1,v.begin()+q3-1);// Erase the elements in the given rangecout<<v.size()<<endl;// Print the size of the vectorfor(inti=0;i<v.size();i++){cout<<v[i]<<" ";// Print the elements of the vector}return0;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Vector-Erase
You are viewing a single comment's thread. Return to all comments →