Posts

Hackerrank's Problem Solving solutions( Bill Division, Sales by Match, Drawing Book ) :

Problem 19: Bill Division 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 , k , i , b , sum = 0 , unfair , fair , refund ; cin >> n >> k ; long long bill [ n ]; for ( i = 0 ; i < n ; i ++) { cin >> bill [ i ]; sum = sum + bill [ i ]; } cin >> b ; unfair = sum / 2 ; fair =( sum - bill [ k ])/ 2 ; refund = unfair - fair ; if ( b == fair ) { cout << "Bon Appetit" ; } else { cout << refund ; } }   This code is simple. There's no need for any explanation.         Problem 20: Sales by Match 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 st

Hackerrank's Problem Solving solutions( Divisible Sum Pairs, Migratory Birds, Day of the Programmer ) :

Problem 16: Divisible Sum Pairs 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 () { int n , k ; cin >> n >> k ; int a [ n ]; for ( int p = 0 ; p < n ; p ++) { cin >> a [ p ]; } int count = 0 ; for ( int i = 0 ; i < n ; i ++)      { for ( int j = i + 1 ; j < n ; j ++)          { if (( a [ i ]+ a [ j ])% k == 0 )              { count ++; } } } cout << count ; } This code is simple. There's no need for any explanation.         Problem 17: Migratory Birds 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

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