4/06/2017

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 "

2 comments:

  1. Domain hosting wiki: for bloggers, business owners and webmasters looking for starting, maintaining and knowing more about domains and hosting
    business

    ReplyDelete
  2. You at that point have an insightful however getting process with respect to making. Incredible outlined all over the place points of interest.
    website marketing

    ReplyDelete