Practice Interview Questions
| Question | Status |
|---|---|
You've been given a list of historical stock prices for Amazon stock throughout a single day. Each index of the list represents the price of the stock at a specific timestamp. Your goal is to write a function that calculates the maximum possible profit from a single purchase and sale of one share of the stock.
You must ensure that the purchase happens before the sale. Additionally, you cannot short sell the stock (i.e., sell before you buy).
Example:
input: [12, 11, 15, 3, 10]
output: 7
This is the maximum profit achieved by buying at 3 and selling at 10.
input: [1, 11, 15, 3, 50]
output: 49
Which is buying at 1 and selling at 50