Skip to main content

Posts

Vector-Erase Hackerrank Solution in C++

 Vector-Erase Hackerrank Solution in C++ For Explanation Watch Video:: Sample Input 6 1 4 6 2 8 9 2 2 4 Sample Output 3 1 8 9 Code: #include   < cmath > #include   < cstdio > #include   < vector > #include   < iostream > #include   < algorithm > using   namespace  std; int  main() {      /* Enter your code here. Read input from STDIN. Print output to STDOUT */         int n;     cin>>n;//6     vector<int> v;     for(int i=0;i<n;i++){         int num;         cin>>num;         v.push_back(num);     }      int x,a,b;     cin>>x>>a>>b;     v.erase(v.begin()+x-1);     v.erase(v.begin()+a-1,v.begin()+b-1);     int len = v.size();     cout<<len<<endl;     for(int i=0;i<len;i++){         cout<<v[i]<<" ";     }      return   0 ; }

Vector-Sort Hackerrank Solution in C++

 Vector-Sort Hackerrank Solution in C++ For Explanation Watch Video:: Sample Input 5 1 6 10 8 4 Sample Output 1 4 6 8 10 Code: #include   < cmath > #include   < cstdio > #include   < vector > #include   < iostream > #include   < algorithm > using   namespace  std; int  main() {      /* Enter your code here. Read input from STDIN. Print output to STDOUT */          int n;     cin>>n;     vector<int>v;     for(int i=0;i<n;i++){         int x;         cin>>x;         v.push_back(x);     }     sort(v.begin(),v.end());     for(int i=0;i<n;i++){         cout<<v[i]<<" ";     }      return   0 ; }

Structs Hackerrank Solution in C++

 Structs Hackerrank Solution in C++ For Explanation Watch Video: Sample Input 15 john carmack 10 Sample Output 15 john carmack 10 Code: #include   < cmath > #include   < cstdio > #include   < vector > #include   < iostream > #include   < algorithm > using   namespace  std; /*     add code for struct here. */ struct Student{     int age,standard;     string first_name,last_name; }; int  main() {     Student st;          cin >> st.age >> st.first_name >> st.last_name >> st.standard;     cout << st.age <<  " "  << st.first_name <<  " "  << st.last_name <<  " "  << st.standard;           return   0 ; }

Strings Hackerrank Solution in C++

 Strings Hackerrank Solution in C++ For Explanation Watch Video: Sample Input abcd ef Sample Output 4 2 abcdef ebcd af Code: #include   < iostream > #include   < string > using   namespace  std; int  main() {      // Complete the program      string a,b;     cin>>a>>b;     cout<<a.length()<<" "<<b.length()<<endl;//4 2     cout<<a+b<<endl;     swap(a[0],b[0]);     cout<<a<<" "<<b;      return   0 ; }

Arrays Introduction Hackerrank Solution in C++

 Arrays Introduction Hackerrank Solution in C++ for Explanation watch video: Sample Input 4 1 4 3 2 Sample Output 2 3 4 1 Code: #include   < cmath > #include   < cstdio > #include   < vector > #include   < iostream > #include   < algorithm > using   namespace  std; int  main() {      /* Enter your code here. Read input from STDIN. Print output to STDOUT */         int n;     cin>>n;//4     int arr[n];     for(int i=0;i<n;i++){         cin>>arr[i];     }      for(int i=n-1;i>=0;i--){         cout<<arr[i]<<" ";     }      return   0 ; }

Pointer Hackerrank Solution in C++

 Pointer Hackerrank Solution in C++ For Explanation Watch Video: #include   < stdio.h > #include <math.h> void  update( int  *a, int  *b) {      // Complete this function          *a = *a + *b;     *b = abs(*a - 2*(*b)); } int  main() {      int  a, b;      int  *pa = &a, *pb = &b;          scanf( "%d %d" , &a, &b);     update(pa, pb);     printf( "%d\n%d" , a, b);      return   0 ; }

Functions Hackerrank Solution in C++

 Functions Hackerrank Solution in C++ For Explanation Watch Video: Sample Input 3 4 6 5 Sample Output 6 Code: #include   < iostream > #include   < cstdio > using   namespace  std; /* Add `int max_of_four(int a, int b, int c, int d)` here. */ int  max_of_four( int  a,  int  b,  int  c,  int  d){      if(a>=b && a>=c && a>=d){         return a;     }else if(b>=a && b>=c && b>=d){         return b;     }else if(c>=a && c>=b && c>=d){         return c;     }else{         return d;     } } int  main() {      int  a, b, c, d;     scanf( "%d %d %d %d" , &a, &b, &c, &d);      int  ans = max_of_four(a, b, c, d);     printf( "%d" , ans);      return   0 ; }