Posts

Showing posts with the label vector

Solution of 'Divisible Sum Pairs' (HackerRank)

Hi all! Here's my solution to the problem 'Divisible Sum Pairs' from HackerRank. #include <bits/stdc++.h> #define int long long #define pb push_back #define fi first #define se second #define pii pair < int,int > using namespace std ; int divisibleSumPairs ( int n , int k , vector < int > ar ) {     int cnt = 0 ;     for ( int i = 0 ; i < n ; i ++){         for ( int j = i + 1 ; j < n ; j ++){             if (( ar [ i ] + ar [ j ] )% k == 0 ) cnt ++;         }     }     return cnt ; } int32_t main () {     int n , k ;     cin >> n >> k ;     vector < int > num ;     for ( int i = 0 ; i < n ; i ++){         int x ;         cin >> x ;         num . pb ( x );     }     int res = divisibleS...

Solution of 'Breaking the Records' (HackerRank)

Hi all! Here's my solution to 'Breaking the Records' of HackerRank. #include <bits/stdc++.h> #define int long long #define pb push_back #define fi first #define se second #define pii pair < int,int > using namespace std ; vector < int > breakingRecords ( vector < int > scores ) {     int M = scores [ 0 ] , m = scores [ 0 ] , M_cnt = 0 , m_cnt = 0 ;     vector < int > temp ;     for ( int i = 0 ; i < scores . size (); i ++){         if ( scores [ i ] < m ){             m = scores [ i ] ;             m_cnt ++;         }         if ( scores [ i ] > M ){             M = scores [ i ] ;             M_cnt ++;         }     }     temp . pb ( M_cnt );     temp . pb ( m_cnt );   ...

Solution of 'Weird Palindrome Making' (Codechef November Challenge 2021 Div3)

Hey guys! Here's my solution to the problem 'Weird Palindrome Making' from Codechef November Challenge 2021 Div3. Comment any suggestions if you have. #include <bits/stdc++.h> #define int long long #define pb push_back #define fi first #define se second #define pii pair < int,int > using namespace std ; int32_t main () {     int t ;     cin >> t ;     while ( t --){         int n ;         cin >> n ;         vector < int > odd ;         for ( int i = 0 ; i < n ; i ++){             int x ;             cin >> x ;             if ( x % 2 != 0 ) odd . push_back ( x );         }         int s = odd . size ();         cout << s / 2 << ' \n ' ;     }   ...

Solution of 'Variable Sized Arrays' (HackerRank)

  Hi guys, here's my solution of the question-'Variable Sized Arrays' from HackerRank. Again, if you guys have any doubts regarding my code, any suggestions for my code or blog, do comment below. TY and Happy Coding! #include   <bits/stdc++.h> using   namespace   std ; int   main () {      int   n , q ;      cin >> n >> q ;      vector < int >  v [ n ];      for ( int   i = 0 ; i < n ; i ++){          int   Q ;          cin >> Q ;          for ( int   j = 0 ; j < Q ; j ++){              int   x ;              cin >> x ;          ...

Solution of 'Less or Equal' (Codeforces)

  Hey guys! Here's my solution of question-'Less or Equal' from Codeforces. I am looking forward to your suggestions for my code or blog. So do comment. TY and Happy coding! question link: https://codeforces.com/contest/977/problem/C #include   <bits/stdc++.h> #define   pair   < int,int >  pp using   namespace   std ; int   main () {      int   n , k ;      cin >> n >> k ;      vector < int >  vec ;      for ( int   i = 0 ; i < n ; i ++){          int   x ;          cin >> x ;          vec . push_back ( x );     }      sort ( vec . begin (), vec . end ());      if (( k != 0 )&&( vec [ k - 1 ] != vec [ k ] )) { cout ...