Posts

Showing posts with the label Number of steps

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