you given a list of prices where prices[i] is the price of a given stock o the i th day write a program to print the maximum profit by choosing a single day to buy a stock and choosing a different day in the future to sell that stock if these is no profit that can be achieved return 0
INPUT
the input is a single line containing space seperated integers
OUTPUT
the output should be an integer
Explanation
in the example the given prices are 7 1 5 3 6 4
buying stocks on day two having price 1 and selling them on the fifth day having price 6 would give the maximum profit which is 6 - 1
so the output should be 5.
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
N = int(input("Enter number of days: "))
a = list(map(int,input("\nEnter the prices: ").strip().split()))[:N]
a.sort()
x=a[N-1]-a[0]
print(x)
Comments
Leave a comment