forked from lothar.buchholz/buy-and-sell-twice
Added description and testdata
parent
fe0587f91c
commit
c86c1ba120
@ -0,0 +1,33 @@
|
|||||||
|
# Buy and Sell Twice
|
||||||
|
|
||||||
|
## Goal
|
||||||
|
Given is the price-development of an arbitrary stock.
|
||||||
|
|
||||||
|
![stock-price over time](doc/stock-price.JPG)
|
||||||
|
|
||||||
|
Suppose you have perfect knowledge and are able to buy and sell the stock **twice**.
|
||||||
|
Write an algorithm that outputs the maximum profit that can be made.
|
||||||
|
|
||||||
|
* The price-development is given for an arbitrary number of days.
|
||||||
|
* A stock can only be sold on the next day.
|
||||||
|
* Stock-prices are given as integers
|
||||||
|
* **The second buy must be made on another date after the first sale**
|
||||||
|
|
||||||
|
### Input
|
||||||
|
A blank-separated array of stock-prices.
|
||||||
|
|
||||||
|
Each position symbolises the stock-price of a given day.
|
||||||
|
|
||||||
|
### Output
|
||||||
|
The maximum profit that can be made within that day.
|
||||||
|
|
||||||
|
### Constraints
|
||||||
|
* 4 <= `days with stock-prices` <= 50
|
||||||
|
* 1 <= `stock-price` <= 2,147,483,647
|
||||||
|
|
||||||
|
### Example
|
||||||
|
**Input:**
|
||||||
|
`12 11 13 9 12 8 14 13 15`
|
||||||
|
|
||||||
|
**Output:**
|
||||||
|
`10`
|
Binary file not shown.
After Width: | Height: | Size: 50 KiB |
@ -1 +1 @@
|
|||||||
rootProject.name = 'template'
|
rootProject.name = 'buy-and-sell-twice'
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
12 11 13 9 12 8 14 13 15, 10
|
||||||
|
310 315 275 295 260 270 290 230 255 250, 55
|
||||||
|
1 2 1 2, 2
|
||||||
|
30 29 28 27, 0
|
||||||
|
0 0 0 0, 0
|
||||||
|
1 0 0 0, 0
|
||||||
|
0 1 1 1, 1
|
||||||
|
226 177 465 365 425 178 328 325 428 165, 538
|
||||||
|
17 261 266 202 246 220 420 390 120 206, 489
|
||||||
|
100 100 40 40 40 70 70 70, 30
|
||||||
|
404 370 48 478 386 157 48 500 443 345, 882
|
||||||
|
404 370 48 478 386 157 152 500 443 345, 778
|
||||||
|
404 370 500 48 478 386 157 152 443 345, 721
|
||||||
|
71622 29778 49278 43266 35321 64004 11569 15358 76325 46324 21209 68079 14505 16821 19481 45622 15044 91459 44742 14731 32402 97619 18531 23351 46294 6443 42565 43976 10390 89339 50414 80745 70068 68925 6460 71966 82808 76650 51168 37177 62789 6277 81398 91852 88771 91089 41410 51305 62464 46015, 171625
|
||||||
|
68941 71600 57442 66633 95154 35131 42141 99811 63172 48106 8475 98869 38000 53928 19145 40854 12274 62055 98571 75665 5203 17280 97920 92034 78957 87443 77211 86404 19438 32631 89925 10809 77909 41390 96105 78035 78285 21024 35521 13358 67241 17009 33381 59371 55581 46024 97347 42960 29149 31541, 183111
|
||||||
|
50475 99931 71645 4336 47287 16439 28493 22806 45724 60734 55445 41931 90369 7416 49331 87500 56317 76342 64624 22835 63579 20350 46476 73361 30444 21531 12824 59458 38753 71993 58684 8816 86301 22702 23316 5111 44782 69841 42297 98631 23986 78318 25994 77107 2844 25915 81602 80089 45663 20118, 179553
|
||||||
|
31415 57223 42652 20693 88629 96495 39321 61282 16147 73229 18819 91069 8584 40336 18775 16328 96503 62165 96146 95743 94957 8990 41718 73242 42438 80072 55036 19633 82085 86487 29457 91539 32383 72521 84821 97564 85805 69144 65539 62642 95499 51508 18834 76619 84593 10853 34456 25352 70698 89234, 176493
|
||||||
|
7580 99445 81284 81448 72881 98705 29410 11793 3574 43699 11461 41322 7330 22885 27159 55953 89069 76241 18863 4448 29988 87771 70582 16636 56644 71363 64399 69087 61412 81993 46698 87018 4856 4805 94973 57420 569 95761 1778 90433 99965 5663 48030 40092 71133 21890 20249 64628 29807 90259, 193379
|
|
Loading…
Reference in New Issue