"This notebook was prepared by [Donne Martin](https://github.com/donnemartin). Source and license info is on [GitHub](https://github.com/donnemartin/interactive-coding-challenges)."
]
},
{
"cell_type":"markdown",
"metadata":{},
"source":[
"# Challenge Notebook"
]
},
{
"cell_type":"markdown",
"metadata":{},
"source":[
"## Problem: Given a list of stock prices on each consecutive day, determine the max profits with k transactions.\n",
"\n",
"* [Constraints](#Constraints)\n",
"* [Test Cases](#Test-Cases)\n",
"* [Algorithm](#Algorithm)\n",
"* [Code](#Code)\n",
"* [Unit Test](#Unit-Test)\n",
"* [Solution Notebook](#Solution-Notebook)"
]
},
{
"cell_type":"markdown",
"metadata":{},
"source":[
"## Constraints\n",
"\n",
"* Is k the number of sell transactions?\n",
" * Yes\n",
"* Can we assume the prices input is an array of ints?\n",
" * Yes\n",
"* Can we assume the inputs are valid?\n",
" * No\n",
"* If the prices are all decreasing and there is no opportunity to make a profit, do we just return 0?\n",
" * Yes\n",
"* Should the output be the max profit and days to buy and sell?\n",
" * Yes\n",
"* Can we assume this fits memory?\n",
" * Yes"
]
},
{
"cell_type":"markdown",
"metadata":{},
"source":[
"## Test Cases\n",
"\n",
"<pre>\n",
"* Prices: None or k: None -> None\n",
"* Prices: [] or k <= 0 -> []\n",
"* Prices: [0, -1, -2, -3, -4, -5]\n",
" * (max profit, list of transactions)\n",
" * (0, [])\n",
"* Prices: [2, 5, 7, 1, 4, 3, 1, 3] k: 3\n",
" * (max profit, list of transactions)\n",
" * (10, [Type.SELL day: 7 price: 3, \n",
" Type.BUY day: 6 price: 1, \n",
" Type.SELL day: 4 price: 4, \n",
" Type.BUY day: 3 price: 1, \n",
" Type.SELL day: 2 price: 7, \n",
" Type.BUY day: 0 price: 2])\n",
"</pre>"
]
},
{
"cell_type":"markdown",
"metadata":{},
"source":[
"## Algorithm\n",
"\n",
"Refer to the [Solution Notebook](). If you are stuck and need a hint, the solution notebook's algorithm discussion might be a good place to start."