Posts

Hackearth's Data Structures solutions( SnackDown Contest, Mark The Answer, Most Frequent ) :

Problem 16: SnackDown Contest Solution: (in c++) ( please guys before moving to the solution try it yourself at least 3-4 times , if you really wanna become a good coder)  #include< bits/stdc++.h > using namespace std ; int main () {      long long t ;     cin >> t ;      while ( t --)      {          long long n , p , q , i ;         cin >> n ;         cin >> p ;         vector < long long > v1 ( p , 0 );          for ( i = 0 ; i < p ; i ++)          {             cin >> v1 [ i ];          }         cin >> q ;         vector < long long > v2 ( q , 0 );          for ( i = 0 ; i < q ; i ++)          {             cin >> v2 [ i ];          }         vector < long long > v3 ( p + q );         merge ( v1 . begin (), v1 . end (), v2 . begin (), v2 . end (), v3 . begin ()); //vector v3=v1+v2         set < long long > s ( v3 . begin (), v3 . end ()); //converting vector v3 into set          long

Hackearth's Data Structures solutions( Charged Up Array, Modify Sequence, EEDC Lab ) :

Problem 13: Charged Up Array Solution: (in c++) ( please guys before moving to the solution try it yourself at least 3-4 times , if you really wanna become a good coder) #include< bits/stdc++.h > using namespace std ; int main () { ios::sync_with_stdio ( 0 ); //to reduce the compile cin . tie ( 0 ); //time a little long long t , i , n ; cin >> t ; while ( t --) { cin >> n ; vector < long long > v ( n ); for ( i = 0 ; i < n ; i ++) { cin >> v [ i ]; } long long sum = 0 ; for ( int i = 0 ; i < n ; i ++) { if ( v [ i ]>=( pow ( 2 , n ))/ 2 ) //see note below { sum += v [ i ]; } } cout << sum % 1000000007 << endl ; } } The total number of subsets of a given array of n elements will be 2^n and therefore the subsets that consist of element Ai will be (2^n)/2 or 2^(n-1) .         Problem 14: Modify Sequence Solution: (in c++) ( please guys before moving

Hackearth's Data Structures solutions( Strange Game, Maximize the Earning, Pepper and Contiguous Even Subarray ) :

Problem 10: Strange Game Solution: (in c++) ( please guys before moving to the solution try it yourself at least 3-4 times , if you really wanna become a good coder) #include< bits/stdc++.h > using namespace std ; int main () {     ios::sync_with_stdio ( 0 ); //helps to reduce the compile time a little cin . tie ( 0 ); //      long long t , n , k ;     cin >> t ;      while ( t --)      { cin >> n >> k ;      long long ct = 0 , i , maxi ; //ct = count      vector < long long > a ( n , 0 ), b ( n , 0 );      for ( i = 0 ; i < n ; i ++)      {          cin >> a [ i ];      }      for ( i = 0 ; i < n ; i ++)      {          cin >> b [ i ];      }      maxi=*max_element ( b . begin (), b . end ())+ 1 ; //max value card bob is having for ( i = 0 ; i < n ; i ++)      {          if ( a [ i ]< maxi )          {              ct = ct +( maxi - a [ i

Hackearth's Data Structures solutions( Long ATM Queue, Polygon Possibility, Micro and Array Update ) :

Problem 7: Long ATM Queue Solution: (in c++) ( please guys before moving to the solution try it yourself at least 3-4 times , if you really wanna become a good coder) #include< bits/stdc++.h > using namespace std ; int main () {      long long n , i , ct = 1 ;     cin >> n ;     vector < long long > v ( n );      for ( i = 0 ; i < n ; i ++)      {         cin >> v [ i ];      }      for ( i = 0 ; i < n - 1 ; i ++)      {          if ( v [ i ]> v [ i + 1 ])          {             ct ++;          }      }     cout << ct ; } This code is simple. There's no need for any explanation. Problem 8: Polygon Possibility Solution: (in c++) ( please guys before moving to the solution try it yourself at least 3-4 times , if you really wanna become a good coder) #include< bits/stdc++.h > using namespace std ; int main () {      long long t , n , i , sum , maxi , s ; //s=side length     cin >> t ; // n=no. of sides, t=test ca