Learn
Practice
Newsletter
Resources
Animations
New
F
Toggle theme
0
F
0
Toggle menu
← Back to All Animations
Best Time to Buy and Sell Stock III
Bookmark
Input
Standard
Increasing
Decreasing
Complex
Custom
prices
=
[3, 3, 5, 0, 0, 3, 1, 4]
prices
3
day 0
3
day 1
5
day 2
0
day 3
0
day 4
3
day 5
1
day 6
4
day 7
buy1
holding #1
sell1
closed #1
buy2
holding #2
sell2
closed #2
track 4 running states; each day the profit cascades buy1 → sell1 → buy2 → sell2
algo
master
.
io
Step:
Start: at most 2 buy/sell transactions on prices = [3, 3, 5, 0, 0, 3, 1, 4]
0 / 34
Input
Standard
Increasing
Decreasing
Complex
Custom
prices
=
[3, 3, 5, 0, 0, 3, 1, 4]
0 / 34
prices
3
day 0
3
day 1
5
day 2
0
day 3
0
day 4
3
day 5
1
day 6
4
day 7
buy1
holding #1
sell1
closed #1
buy2
holding #2
sell2
closed #2
track 4 running states; each day the profit cascades buy1 → sell1 → buy2 → sell2
algo
master
.
io
Step:
Start: at most 2 buy/sell transactions on prices = [3, 3, 5, 0, 0, 3, 1, 4]