Skip to content

Commit

Permalink
Merge pull request #144 from Akshatkr25/main
Browse files Browse the repository at this point in the history
Stocks buy and sell problem
  • Loading branch information
aman-raza authored Oct 3, 2021
2 parents 5996810 + 2c3ee4f commit 6145576
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions stocks_Buy_And_Sell_Problem.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <bits/stdc++.h>

using namespace std;

int stocksProfit(int arr[],int n){
int minPrice= INT_MAX;
int maxProfit = 0;
for(int i=0 ; i<n ; i++){
minPrice = min(minPrice , arr[i]);
maxProfit = max(maxProfit , arr[i] - minPrice);
}
return maxProfit;
}

int main()
{
int n;
cin>>n;
int arr[n];
for(int i =0 ; i<n ; i++){
cin>>arr[i];
}
cout<<"Maximum Profit: "<<stocksProfit(arr , n)<<" Rs.";

return 0;
}

0 comments on commit 6145576

Please sign in to comment.