Back to exercises

Best Time to Buy and Sell Stock

Walk the array once, keep the lowest price so far, and compute the best profit if you sold today.

Coding Exercises Easy O(n)

Best Time to Buy and Sell Stock

Walk the array once, keep the lowest price so far, and compute the best profit if you sold today.

Find the maximum profit from one buy and one sell of a stock price series.