Skip to content

Latest commit

 

History

History
9 lines (5 loc) · 672 Bytes

README.md

File metadata and controls

9 lines (5 loc) · 672 Bytes

Sell, sell, sell!

Suppose we are given an array of n integers which represent the value of some stock over time. Assuming you are allowed to buy the stock exactly once and sell the stock once, what is the maximum profit you can make? Can you write an algorithm using Python that takes in an array of values and returns the maximum profit?

For example, if you are given the following array:

2, 7, 1, 8, 2, 8, 14, 25, 14, 0, 4, 5

The maximum profit you can make is 24 because you would buy the stock when it's price is 1 and sell when it's 25. Note that we cannot make 25, because the stock is priced at 0 after it is priced at 25 (e.g you can't sell before you buy).