Thursday, 6 April 2017

Geeksforgeeks Solution For " Two Repeated Elements "

GeeksforGeeks Solution For Hard Domain .Below You Can Find The Solution Of  School Basic ,Easy ,Medium . Or Hackerrank Solution You Can Also Direct Submit Your Solution to Geeksforgeeks Same Problem .You Need to login then you can submit you answers 

Problem :- Two Repeated Elements

Submit Your Solution :- Click Here 

Solution :- 

#include<iostream>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--){
   int n;
   cin>>n;
   int a[n+2],b[n+2]={};

   for(int i=0;i<n+2;i++){
       cin>>a[i];
       b[a[i]]=b[a[i]]+1;
       if(b[a[i]]==2)
           cout<<a[i]<<" ";
   }
   cout<<endl;
}
return 0;
}

Output:-



Geeksforgeeks Solution For " Two Repeated Elements "

Geeksforgeeks Solution For " Sum of Middle Elements of two sorted arrays "

GeeksforGeeks Solution For Hard Domain .Below You Can Find The Solution Of  School Basic ,Easy ,Medium . Or Hackerrank Solution You Can Also Direct Submit Your Solution to Geeksforgeeks Same Problem .You Need to login then you can submit you answers 

Problem :- Sum of Middle Elements of two sorted arrays

Submit Your Solution :- Click Here 

Solution :- 

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
int t,n,val;
cin>>t;
while(t--){

cin>>n;
int a[n],b[n];
vector<int>c(2*n);
for(int i=0;i<n;i++){
cin>>a[i];
}

for(int i=0;i<n;i++){
cin>>b[i];
}
merge(a,a+n,b,b+n,c.begin());
int s=c.size();
cout<<(c[(s/2)-1]+c[s/2])<<endl;

}
}

Output:-



Geeksforgeeks Solution For " Sum of Middle Elements of two sorted arrays "

Geeksforgeeks Solution For " Stock buy and sell "

GeeksforGeeks Solution For Hard Domain .Below You Can Find The Solution Of  School Basic ,Easy ,Medium . Or Hackerrank Solution You Can Also Direct Submit Your Solution to Geeksforgeeks Same Problem .You Need to login then you can submit you answers 

Problem :- Stock buy and sell

Submit Your Solution :- Click Here 

Solution :- 

#include<bits/stdc++.h>
using namespace std;
int main()
 {
int t;
    cin>>t;
    while(t--)
    {
        int n;
   cin>>n;
   int a[n];
   for(int i=0;i<n;i++)
       cin>>a[i];
   int buy=0,sell=0;
   bool key=false;
   for(int i=1;i<n;i++)
   {
       if(a[i]>a[i-1])
           sell++;
       else
       {
           if(buy!=sell)
           {
               cout<<"("<<buy<<" "<<sell<<") ";
               key=true;
           }
           buy=sell=i;
       }
   }
   if(buy!=sell)
   {
       cout<<"("<<buy<<" "<<sell<<") ";
        key=true;
   }
   if(!key)
        cout<<"No Profit";
   cout<<endl;       
    }
return 0;
}

Output:-



Geeksforgeeks Solution For " Stock buy and sell "

Geeksforgeeks Solution For " Reverse Coding "

GeeksforGeeks Solution For Hard Domain .Below You Can Find The Solution Of  School Basic ,Easy ,Medium . Or Hackerrank Solution You Can Also Direct Submit Your Solution to Geeksforgeeks Same Problem .You Need to login then you can submit you answers 

Problem :- Reverse Coding

Submit Your Solution :- Click Here 

Solution :- 

#include <iostream>
using namespace std;

int main() {
int t;
cin>>t;
while(t--){
   int n,m;
   cin>>n>>m;
   int c=(n*(n+1))/2;
   if(c==m)
       cout<<1<<endl;
        else
            cout<<0<<endl;
}
return 0;
}

Output:-



Geeksforgeeks Solution For " Reverse Coding "

Geeksforgeeks Solution For " Move all negative elements to end "

GeeksforGeeks Solution For Hard Domain .Below You Can Find The Solution Of  School Basic ,Easy ,Medium . Or Hackerrank Solution You Can Also Direct Submit Your Solution to Geeksforgeeks Same Problem .You Need to login then you can submit you answers 

Problem :- Move all negative elements to end

Submit Your Solution :- Click Here 

Solution :- 

#include <iostream>
#include <vector>
using namespace std;

int main() {
int t;
    cin>>t;
    while(t--){
        int no,p=0,n=0;
        cin>>no;
        vector<int> po,ng;
        int a[no];
        for(int i=0;i<no;i++){
            cin>>a[i];
            if(a[i]>=0){
                p++;
                po.push_back(a[i]);
            }    
            else{
                n++;
                ng.push_back(a[i]);
            }    
        }
        for(int i=0;i<p;i++)
            a[i]=po[i];
        for(int i=0;i<n;i++)    
            a[p+i]=ng[i];
        for(int i=0;i<no;i++)    
            cout<<a[i]<<" ";
        cout<<endl;    
    }
return 0;
}

Output:-



Geeksforgeeks Solution For " Move all negative elements to end "

Geeksforgeeks Solution For " Maximum repeating number "

GeeksforGeeks Solution For Hard Domain .Below You Can Find The Solution Of  School Basic ,Easy ,Medium . Or Hackerrank Solution You Can Also Direct Submit Your Solution to Geeksforgeeks Same Problem .You Need to login then you can submit you answers 

Problem :- Maximum repeating number

Submit Your Solution :- Click Here 

Solution :- 

#include <bits/stdc++.h>
using namespace std;

int main() {
int t;
cin>>t;
while(t--){
   int n, k;
   cin>>n>>k;
   int a[n], b[n]={};
   for(int i=0; i<n; i++){
       cin>>a[i];
       b[a[i]]=b[a[i]]+1;
   }
   int index=0,max_v=b[0];
           
            for(int i=0;i<k;i++)
                if(b[i]>max_v){
                    max_v=b[i];
                    index=i;
                }
            cout<<index<<endl;
}
return 0;
}

Output:-



Geeksforgeeks Solution For " Maximum repeating number "

Geeksforgeeks Solution For " Maximum no of 1's row "

GeeksforGeeks Solution For Hard Domain .Below You Can Find The Solution Of  School Basic ,Easy ,Medium . Or Hackerrank Solution You Can Also Direct Submit Your Solution to Geeksforgeeks Same Problem .You Need to login then you can submit you answers 

Problem :- Maximum no of 1's row

Submit Your Solution :- Click Here 

Solution :- 

#include <iostream>
using namespace std;

int main() {
int t;
cin>>t;
while(t--){
   int r,c,i,j,row_n,prev_c=0,cur_c;
   cin>>r>>c;
   bool a[r][c];
   for(i=0; i<r; i++)
       for(j=0; j<c; j++)
           cin>>a[i][j];
   
   for(i=0; i<r; i++){
       cur_c=0;
       for(j=0; j<c; j++){
          if(a[i][j]==1)
           cur_c++;
       }   
       if(cur_c>prev_c){
            row_n=i;
       prev_c=cur_c;
       }
               
   }     
   cout<<row_n<<endl;
}
return 0;
}

Output:-



Geeksforgeeks Solution For " Maximum no of 1's row "

Geeksforgeeks Solution For " Key Pair "

GeeksforGeeks Solution For Hard Domain .Below You Can Find The Solution Of  School Basic ,Easy ,Medium . Or Hackerrank Solution You Can Also Direct Submit Your Solution to Geeksforgeeks Same Problem .You Need to login then you can submit you answers 

Problem :- Key Pair

Submit Your Solution :- Click Here 

Solution :- 

#include <iostream>
using namespace std;

int main() {
int t;
cin>>t;
while(t--){
   int n,x;
   cin>>n>>x;
   int a[n];
   for(int i=0; i<n; i++)
       cin>>a[i];
   int key=0;
   for(int i=0; i<n-1; i++)
       for(int j=i+1; j<n; j++){
           if((a[i]+a[j])==x){
               key=1;
               break;
           }
       }
       
   
   if(key)
       cout<<"Yes"<<endl;
   else
       cout<<"No"<<endl;
}
return 0;
}

Output:-



Geeksforgeeks Solution For " Key Pair "

Geeksforgeeks Solution For " Element that appears once where every element occurs twice "

GeeksforGeeks Solution For Hard Domain .Below You Can Find The Solution Of  School Basic ,Easy ,Medium . Or Hackerrank Solution You Can Also Direct Submit Your Solution to Geeksforgeeks Same Problem .You Need to login then you can submit you answers 

Problem :-  Element that appears once where every element occurs twice

Submit Your Solution :- Click Here 

Solution :- 

#include <iostream>
using namespace std;

int appearance(int a[],int n){
    int res=a[0];
    //int bit_mask;
    for(int i=1; i<n; i++){
        res=res^a[i];
    }
    return res;
}

int main() {
int t;
cin>>t;
while(t--){
   int n;
   cin>>n;
   int a[n];
   for(int i=0;i<n;i++)
       cin>>a[i];
   cout<<appearance(a,n)<<endl;
   
}
return 0;
}

Output:-



Geeksforgeeks Solution For " Element that appears once where every element occurs twice "
Add caption

Geeksforgeeks Solution For " Anagram "

GeeksforGeeks Solution For Hard Domain .Below You Can Find The Solution Of  School Basic ,Easy ,Medium . Or Hackerrank Solution You Can Also Direct Submit Your Solution to Geeksforgeeks Same Problem .You Need to login then you can submit you answers 

Problem :- Anagram

Submit Your Solution :- Click Here 

Solution :- 

#include <bits/stdc++.h>
using namespace std;

int main() {
int t;
cin>>t;
while(t--){
   string x,y;
   cin>>x>>y;
   auto key=false;
   if(x.length()<y.length()||y.length()<x.length())
   {
       key=true;
   }
           else{
       sort(x.begin(),x.end());
   sort(y.begin(),y.end());
   
   for(auto i=0;i<x.length();i++)
       if(x[i]!=y[i]){
       key=true;
       break;
      }
           }
  if(key)
       cout<<"NO"<<endl;
  else
       cout<<"YES"<<endl;
      
}   
}

Output:-



Geeksforgeeks Solution For " Anagram "