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:-
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