2291. Maximum Profit From Trading Stocks ¶
Approach 1: 2D DP¶
- Time: $O(n \cdot \texttt{budget})$
- Space: $O(n \cdot \texttt{budget})$
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
Approach 2: 1D DP¶
- Time: $O(n \cdot \texttt{budget})$
- Space: $O(\texttt{budget})$
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|