Skip to content

Commit 86c3c7b

Browse files
committed
sell, buy stocks to max profit
1 parent bc006ea commit 86c3c7b

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Sell Buy Stocks to Max Profit.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
p = list(map(int, input().split())) #Enter the prices of each day
2+
3+
maxProfit = 0
4+
currentMax = 0
5+
6+
for i in reversed(p):
7+
currentMax = max(currentMax, i)
8+
profit = currentMax - i
9+
maxProfit = max(profit, maxProfit)
10+
11+
print("Buy stock when price is:", currentMax-maxProfit) #Buying Price
12+
print("Sell stock when price is:", currentMax) #Selling Price
13+
print("Maximum profit earned:", maxProfit) #Profit Earned

0 commit comments

Comments
 (0)