Posts

Showing posts from August, 2020

HackerEarth's basic programming solutions( Number of steps, Friend's Relationship ) :

Problem 45: Number of steps 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 , count = 0 ; cin >> n ; int a [ n ], b [ n ]; int m = 1000000000 ; for ( int i = 0 ; i < n ; i ++) { cin >> a [ i ]; m = min ( m , a [ i ]); } for ( int j = 0 ; j < n ; j ++) { cin >> b [ j ]; } bool notSame = true ; while ( notSame ) { notSame = false ; for ( int i = 0 ; i < n ; i ++) { while ( a [ i ]> m && a [ i ]!= 0 ) { a [ i ]= a [ i ]- b [ i ]; notSame = true ; count ++; } if ( m > a [ i ]) m = a [ i ]; if ( m < 0 ) break ; } } if ( m < 0 ) cout<<- 1 ; else cout << count ; } Stay tuned for the explanation!!!         Problem 46: Friend's Relationship Solution: (in c++) ( please guys before moving to the solu

HackerEarth's basic programming solutions( Minimize Cost, Magical Word, Best Index ) :

Problem 42: Minimize Cost 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) "Still working on this problem....."         Problem 43: Magical Word 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 t ;    cin >> t ;     while ( t --)     {        int l ;       string s ;       cin >> l >> s ;        for ( int i = 0 ; i < s . length (); i ++)         {           if ( s [ i ]<= 69 && s [ i ]>= 65 )          s [ i ]= 'C' ;           else if ( s [ i ]<= 72 && s [ i ]>= 70 )          s [ i ]= 'G' ;           else if ( s [ i ]<= 76 && s [ i ]>= 73 )          s [ i ]= 'I' ;           else if ( s [ i ]<= 81 &&

HackerEarth's basic programming solutions( Back to School, Minimum Steps, Cipher ) :

Problem 39: Back to School 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 a , b , c ;     cin >> a >> b >> c ;      if ( a > b && a > c )      {         cout << a ;      }      else if ( b > a && b > c )      { cout << b ;      }      else {         cout << c ;      }     } This code is simple. There's no need for any explanation.         Problem 40: Minimum Steps 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 test , count , k , m , n , x ; cin >> test ; while ( test --) {         count = 0 ; cin >

HackerEarth's basic programming solutions( Divisible, Seven-Segment Display, A. Movement ) :

Problem 36: Divisible 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 , sum = 0 , i ; cin >> n ; long long a [ n ]; for ( i = 0 ; i < n ; i ++) { cin >> a [ i ]; } for ( i = 0 ; i < n / 2 ; i ++) //considering first half elements { while ( a [ i ]>= 10 ) //using this you can find first digit of a number { a [ i ]= a [ i ]/ 10 ; }   if ( i % 2 == 0 ) //see note below { sum += a [ i ]; } else { sum +=( a [ i ] *- 1 ); } } for ( i = n / 2 ; i < n ; i ++) //considering next half elements { a [ i ]= a [ i ]% 10 ; //using this you can find the last digit of a number   if ( i % 2