You're a buyer/seller and your business is at stake. You need to make profit... Or at least, you need to lose the least amount of money! Knowing a list of prices for buy/sell operations, you need to pick two of them. Buy/sell market is evolving across time and the list represent this evolution. First, you need to buy one item, then sell it later. Find the best profit you can do.
A list of prices (integers), of length 2 or more.
The result of the best buy/sell operation, as an integer.
Given an array of prices [3, 10, 8, 4], the best profit you could make would be 7 because you buy at 3 first, then sell at 10.
max_profit([10, 7, 5, 8, 11, 9])
max_profit([10, 7, 5, 4, 1])
Want to propose a challenge idea for a future post? Email email@example.com with your suggestions!