Problem:- Vector Erase Hacker Rank Solution or Vector-Erase hacker rank solution c++ orMulti Level Inheritance in java or Vector-Erase solution or Vector-Erase solution in C++ or Vector-Erase hacker rank solution in Java or Vector-Erase hacker rank solution c++ or Vector-Erase hacker rank solution c++ or Vector-Erase program in c or Vector-Erase solution in C or Hacker Rank Solution For Vector-Erase in C++ or Vector-Erase in C++ or Hacker Rank solution for Vector-Erase in C++.
Explanation:- Check this some vector functions.
erase(int position):
Removes the element present at the position.
Ex: v.erase(v.begin()+4); (erases the 5th element of the vector v)
erase(int start,int end):
Removes the elements in the range from start to end inclusive of the start and exclusive of the end.
Ex: v.erase(v.begin()+2,v.begin()+5);
erases all the elements from the third element to the fifth element.
Check- Geeksforgeeks solution for School, Basic, Easy, Medium, Hard Domain.
Submit your solution here:- Click here
Solution:-
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int n,i,b,c,d,size;
cin>>n;
vector<int> a;
for(i=0;i<n;i++)
{
int x;
cin>>x;
a.push_back(x);
}
cin>>b>>c>>d;
a.erase(a.begin()+b-1);
a.erase(a.begin()+c-1,a.begin()+d-1);
size=a.size();
cout<<size<<endl;
for(i=0;i<size;i++)
cout<<a[i]<<" ";
return 0;
}
Output:-

You May Like This:-
1. Hacker Rank Solution for 30 Days of Code
2. Hacker Rank solution for Attribute Parser
3. Java Program For Find The Gross Salary Of An Employee
4. C++ Program For School Management System ( SMS Project ) With Source Code
5. Hacker Rank Solution For Mini-Max Sum
6. Hacker Rank Solution Program In C++ For " Vector-Sort"
7. Hacker Rank Solution Program In C++ For " Lower Bound-STL"
8. Hacker Rank Solution Program In C++ For " Sets-STL "
9. Hacker Rank Solution Program In C++ For " Maps-STL"
10. Hacker Rank Solution Program In C++ For " Print Pretty"
Explanation:- Check this some vector functions.
erase(int position):
Removes the element present at the position.
Ex: v.erase(v.begin()+4); (erases the 5th element of the vector v)
erase(int start,int end):
Removes the elements in the range from start to end inclusive of the start and exclusive of the end.
Ex: v.erase(v.begin()+2,v.begin()+5);
erases all the elements from the third element to the fifth element.
Check- Geeksforgeeks solution for School, Basic, Easy, Medium, Hard Domain.
Submit your solution here:- Click here
Solution:-
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int n,i,b,c,d,size;
cin>>n;
vector<int> a;
for(i=0;i<n;i++)
{
int x;
cin>>x;
a.push_back(x);
}
cin>>b>>c>>d;
a.erase(a.begin()+b-1);
a.erase(a.begin()+c-1,a.begin()+d-1);
size=a.size();
cout<<size<<endl;
for(i=0;i<size;i++)
cout<<a[i]<<" ";
return 0;
}
Output:-
You May Like This:-
1. Hacker Rank Solution for 30 Days of Code
2. Hacker Rank solution for Attribute Parser
3. Java Program For Find The Gross Salary Of An Employee
4. C++ Program For School Management System ( SMS Project ) With Source Code
5. Hacker Rank Solution For Mini-Max Sum
6. Hacker Rank Solution Program In C++ For " Vector-Sort"
7. Hacker Rank Solution Program In C++ For " Lower Bound-STL"
8. Hacker Rank Solution Program In C++ For " Sets-STL "
9. Hacker Rank Solution Program In C++ For " Maps-STL"
10. Hacker Rank Solution Program In C++ For " Print Pretty"
0 Comments: