Skip to content

Latest commit

 

History

History
14 lines (9 loc) · 607 Bytes

README.md

File metadata and controls

14 lines (9 loc) · 607 Bytes

Build Status

buysell

Max buy-sell profit problems.

background

Given a one-dimensional array of stock prices, what is the maximum profit that could have been achieved given a specific number of transactions?

You can only buy/sell one share at a time. You must alternate buying and selling (i.e. you can't hold shares)

e.g.

Given [1, 2, 3, 4, 5, 1, 3] as a stream of prices, with 4 transactions, the best profit you could make is 6 - buy on day 0, sell day 4, buy day 5, sell day 6.