Posts

Showing posts from July, 2020

Hackerrank vector erase question solution in C++

Here's the solution to Hackerrank's vector erase question.The code is optimised and pass all test result #include   < cmath > #include   < cstdio > #include   < vector > #include   < iostream > #include   < algorithm > using   namespace   std ; int   main ()   { int   size , no ;   cin >> size ;   vector < int > v1 ;   for ( int   i = 0 ; i < size ; i ++)   { cin >> no ;    v1 . push_back ( no );   }   int   query1 ;   cin >> query1 ;   query1 = query1 - 1 ;   v1 . erase ( v1 . begin ()+ query1 );   int   pos1 , pos2 ;   cin >> pos1 >> pos2 ;   v1 . erase ( v1 . begin ()+ pos1 - 1 , v1 . begin ()+ pos2 - 1 );   cout << v1 . size ()<< endl ;   for ( int   i = 0 ; i < v1 . size (); i ++)   {  ...