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 "

4 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
  3. Can I get an information on how to write a case study format APA? I struggle with this assignment. I have to accomplish this task by the next week. I hope to be helped out by somebody.

    ReplyDelete
  4. Hey guys! I am a decorator of weedings and create different wedding-related things in order to make halls more beautiful, moreover I want to become more and more proffessional in that sphere so should pass different tests and essays in order to get the promotion and become more quialified, so I will definitely use your article if you are not against, and help of the proffessional writers at prime-resume.com who will be ready to conduct instead of me my resume

    ReplyDelete