Added description and testdata

master
Christoph Prybila 4 years ago
parent 7562c5ab33
commit 44c919f873

@ -0,0 +1,32 @@
# Buy and Sell Once
## 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 once.
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
### 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
* 2 <= `days with stock-prices` <= 50
* 1 <= `stock-price` <= 2,147,483,647
### Example
**Input:**
`310 315 275 295 260 270 290 230 255 250`
**Output:**
`30`

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

@ -1 +1 @@
rootProject.name = 'template'
rootProject.name = 'buy-and-sell-once'

@ -0,0 +1,17 @@
310 315 275 295 260 270 290 230 255 250, 30
1 2, 1
30 29, 0
0 0, 0
1 0, 0
0 1, 1
226 177 465 365 425 178 328 325 428 165, 288
17 261 266 202 246 220 420 390 120 206, 403
100 100 40 40 40 70 70 70, 30
404 370 48 478 386 157 48 500 443 345, 452
404 370 48 478 386 157 152 500 443 345, 452
404 370 500 48 478 386 157 152 443 345, 430
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, 86050
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, 92717
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, 94295
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, 88980
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, 99396
1 310 315 275 295 260 270 290 230 255 250 30
1 310 315 275 295 260 270 290 230 255 250 30
2 1 2 1
3 30 29 0
4 0 0 0
5 1 0 0
6 0 1 1
7 226 177 465 365 425 178 328 325 428 165 288
8 17 261 266 202 246 220 420 390 120 206 403
9 100 100 40 40 40 70 70 70 30
10 404 370 48 478 386 157 48 500 443 345 452
11 404 370 48 478 386 157 152 500 443 345 452
12 404 370 500 48 478 386 157 152 443 345 430
13 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 86050
14 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 92717
15 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 94295
16 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 88980
17 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 99396
Loading…
Cancel
Save