Posts

Hackearth's Data Structures solutions( Takeoff, Help Jarvis! , Pairs Having Similar Elements ) :

Problem 4: Takeoff 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 --)      {          long long n , p , q , r , i , check , ct = 0 ;         cin >> n >> p >> q >> r ;          for ( i = 1 ; i <= n ; i ++)          {             check = 0 ; if ( i % p == 0 )              { check ++;              }              if ( i % q == 0 )              { check ++;              } if ( i % r == 0 )              { check ++;              }              if ( check == 1 )              {                 ct ++;              }          }         cout << ct << endl ;      } } This code is simple. There's no need for any explanation.         Problem 5: Help Jarvis! Solution: (in c++) ( please gu

Hackerearth's data structures problems solutions( Odd one Out, Help them Out, Hamiltonian and Lagrangian ) :

Problem 1: Odd one Out 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 ); //read here to understand cin . tie ( 0 ); long long i , n , s = 0 ; cin >> n ;      long long a [ n ]; for ( int i = 0 ; i < n - 1 ; i ++) { cin >> a [ i ];         s += a [ i ]; //s will store the sum of array elements      } cout <<( n * n )- s ; //see note below } Using arithmetic progression sum formula it can be proved that: 1 + 3 + 5 + 7 +.......+n  = n*n Since sum of A.P = (n/2)*(2*a + (n-1)*d) here  a = 1 , d = 2 Therefore, sum of A.P = n*n Hence by subtracting the sum of given elements from the original sum of the set of odd numbers will give us the missing odd number.   Problem 2: Help them Out Solution: (in c++) ( please guys before mo

Hackerearth's python problems solutions( Jadoo vs Koba, Jadoo and DNA Transcription, Jadoo Hates Numbers, 13 Reasons Why, Chacha!! O Chacha ) :

Problem 1: Jadoo vs Koba Solution: (in python 3.8) ( please guys before moving to the solution try it yourself at least 3-4 times , if you really wanna become a good coder) for i in range ( ord ( 'F' ), ord ( 'Q' )): #see note below print ( i )   ord() function returns the ASCII value of a character inside it's parenthesis. You can also wrap up this question in one line using list comprehensions :   [ print ( i ) for i in range ( ord ( 'F' ), ord ( 'Q' ))]           Problem 2: Jadoo and DNA Transcription Solution: (in python 3.8) ( please guys before moving to the solution try it yourself at least 3-4 times , if you really wanna become a good coder) s = input () for i in s :      if i!= "G" and i!= "C" and i!= "T" and i!= "A" :          print ( "Invalid Input" )         exit () for i in s :      if i== "G" :          print ( "C" , end= "&qu

How learning STL in c++ can help you code faster , shorter and simple?

All you need to know about C++ STL is here! After you have finished c++ basics and wondering what to do next then the best choice from my point of view is to start learning c++ STL .  Are you tired of writing big codes and just want to use functions directly like you use to do in strings in c ?  Along with a STL you also get many direct functions. Using STL for different data storage containers or data structures like arrays, stacks, queues, lists (both singly linked list and doubly linked list) etc, you do not have to write big and lengthy codes for creating them, inserting elements into them and a whole lot number of other operations. STLs are also really really helpful in competitive programming . NOTE : Prior to doing STL, you should learn about templates in c++ which comes under objective c++. But since you have to use direct functions, that's why not that much deep knowledge is required. If you can remember the syntax of a given function, that's fine also. What is STL (n

Hackerrank's Problem Solving solutions( Number Line Jumps, Breaking the Records, Sub-array Division ) :

Problem 13: Number Line Jumps 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 x1 , v1 , x2 , v2 ; cin >> x1 >> v1 >> x2 >> v2 ; if ( v1 != v2 ) { long long n =(( x2 - x1 )/( v1 - v2 )); if ( n > 0 && ( n * v1 + x1 == n * v2 + x2 )) //i calculated this formula using maths { cout << "YES" ; } else { cout << "NO" ; } } if ( x1 == x2 || v1 == v2 ) { cout << "NO" ; } } This code is simple. There's no need for any explanation.         Problem 14: Breaking the Records 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/