"If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design an algorithm to find the maximum profit."

I misunderstood the above sentence as at most either buy or sell one share of stock on a single day. In that case, I buy at a local minimum price and sell it at a local maximum to reach a maximum total profit.

Please consider changing it to something like the following:

`If you were only permitted to complete at most one buy and at most one sell during the whole period of days, design an algorithm such that your profit, i.e., sell price minus buy price, is maximized. Note that you can only not sell a stock before you buy one.`

`For example:`

`[1,2,3,4] ==> returns 3 (buy at 1 and sell at 4)`

`[4,3,2,1] ==> returns 0 (don't buy)`

`[4,10,25,2,10] ==> returns 21 (buy at 4 and sell at 25)`