Market Day (Arrays & Lists)
You know the price of a potion on each of n days. Buy on one day and sell on a later day. Print the biggest profit you can make, or 0 if no trade makes money.
Input: n (1 to 1000), then n prices from 0 to 10^4.
Output: One integer.
Difficulty: Easy. Write your answer in the browser editor, run the examples, then submit it against hidden tests. Python and JavaScript are free; other languages are part of licode Club.
Hint
- Walk the days once, remembering the cheapest price so far.