Stock Buy Sell to Maximize Profit
We’re given an array of daily stock prices (integers for simplicity). Return the buying and selling prices for making the maximum profit.
The values in the array represent the cost of stock each day. As we can buy and sell the stock only once, we need to find the best buy and sell prices that maximize profit (or minimized loss) over a given span of time.
We need to maximize the profit from a single buy and sell. If we can’t make any profit, we’ll try to minimize the loss.
For the below examples, the buying and selling prices for making a maximum profit are highlighted: