Skip to content

Instantly share code, notes, and snippets.

@lazycipher
Created May 7, 2019 14:39
Show Gist options
  • Save lazycipher/6f6fd5be9c197e8190dcf53f74dab8d1 to your computer and use it in GitHub Desktop.
Save lazycipher/6f6fd5be9c197e8190dcf53f74dab8d1 to your computer and use it in GitHub Desktop.
HackerRank Vector Erase Problem in C++
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
vector<int> ins;
int n, erSingle, erRangeS, erRangeE;
cin>>n;
while(n){
int val;
cin>>val;
ins.push_back(val);
n--;
}
cin>>erSingle;
ins.erase(ins.begin()+(erSingle-1));
cin >> erRangeS >> erRangeE;
ins.erase(ins.begin()+erRangeS-1, ins.begin()+erRangeE-1);
cout<<ins.size()<<endl;
for(int i = 0; i<ins.size(); i++){
cout<<ins[i]<<" ";
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment