Answer to Question #289754 in Python for pooja

Question #289754

Did you mean: Jatin is a college student and he got his first salary from an internship. his plan is to buy one stock on a particular day and then sell it on another day. He can trade (buy & sell) the stock only once. he has one time use magic spell which he used to get the stock prices N future consecutive days. based on this information and his strategy determine the maximum profit he can make. in the given list of price, the price of stock on the ith day is denoted by prices[i]. If there is no profit that can be achieved , return 0.


SAMPLE INPUT 1:

7 1 5 3 6 4

SAMPLE OUTPUT 1:

5


SAMPLE INPUT 2:

1 11 13 21 19

SAMPLE OUTPUT 2:

20


1
Expert's answer
2022-01-22T16:32:44-0500
arr = list(map(int,input().split()))


Min = 100000000
Max = 0


for it in arr:
    Min = min(Min,it)
    Max = max(Max,it-Min)
    
print(Max)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS