Buy and Sell Stock (6 Qs)

Series of problems related to "Best Time to Buy and Sell Stock"

We could solve these problems using the same concept, Final State Machine. Only two states are required for us to come up with the solution:

  • Hold State - The profit when we hold the stock. It could indicate that we already hold the stock and don't sell it or just buy a stock.

  • No-hold State - The profit when we don't hold the stock. It could indicate that we haven't bought any stocks or just sell a stock.

Note that we could decide not to perform any actions (either buy or sell) in a certain day if we cannot gain more profits.

Related problems (follow the order to solve each problem):

Last updated