In this HackerRank Sets-STL problem in c++, you will be given Q queries. each query is of one of the following types.
  1. Add an element to the set.
  2. Delete an element from the set
  3. if the number is present in the set, then print "Yes" else print "No".

HackerRank Sets-STL in C++ problem solution

 

HackerRank Sets-STL in C++ problem solution

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;


int main() {
    set<long long int> st;
    int n,q;
    long long int x;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>q>>x;
        if(q==1)
            st.insert(x);
        else if(q==2)
            st.erase(x);
        else if(q==3){
            set<long long int>::iterator it=st.find(x);
            if(it==st.end())
                cout<<"No"<<endl;
            else 
                cout<<"Yes"<<endl;
        }
            
    }
    return 0;
}