ExpertAlgorithms50 points
Best day to buy and sell
A small trader tracks the daily price of a commodity. She can buy once and sell once later (the sale must be on a day after the purchase). She wants to know the best profit she could have made.
Task: the first line holds n, the second line holds n prices separated by spaces. Print the maximum profit. If no profit is possible, print 0.
Sample test
Input
6 7 1 5 3 6 4
Expected output
5
Your answer is also checked against 3 hidden tests.
Need a hint?
Walk through the prices once, remembering the lowest price so far and the best profit so far.
Python 3
50 pts
Loading editor...
Log in or create a free account to run your code, submit and earn points.
Run your code to see the output here. Ctrl + Enter also runs it.
