Problem of the day
You can’t sell a stock before you buy one.
Let’s say, ‘PRICES’ =[7, 1, 5, 4, 3, 6]
Purchase stock on day two, where the price is one, and sell it on day six, where the price is 6, profit = 6 - 1 = 5.
Hence we return 5.
The first line contains an integer ‘N’ denoting the size of the array ‘PRICES’.
The second line includes ‘N’ integers denoting the elements of the array ‘PRICES’.
Return the maximum profit you can achieve from this transaction.
You don't need to print anything. Just implement the given function.
1 <= 'N' <= 10^5
1<= ‘PRICES[i]’<= 10^9, 0<=i<’N-1’
Time Limit: 1 sec
6
7 1 5 4 3 6
5
Purchase stock on day two, where the price is one, and sell it on day six, where the price is 6, profit = 6 - 1 = 5.
5
5 4 3 2 1
0