Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Minimum Cost to Cut a Stick
Bookmark
Recursion
Memoization
Bottom-Up DP
Input
Example 1
Example 2
Example 3
Example 4
Custom
n
=
7
,
cuts
=
[1, 3, 4, 5]
boundaries (endpoints + sorted cuts)
0
1
2
3
4
5
0
1
3
4
5
7
i
j
k
Call Stack
solve(2,4)
solve(2,5)
solve(1,5)
solve(0,5)
solve(2, 3) + solve(3, 4)
boundaries (endpoints + sorted cuts)
0
1
2
3
4
5
0
1
3
4
5
7
i
j
Call Stack
solve(3,5)
solve(1,5)
solve(0,5)
solve(3, 5) on segment [4, 7]
boundaries (endpoints + sorted cuts)
0
1
2
3
4
5
0
1
3
4
5
7
i
j
k
Call Stack
solve(1,4)
solve(1,5)
solve(0,5)
minCost = 2
boundaries (endpoints + sorted cuts)
0
1
2
3
4
5
0
1
3
4
5
7
i
j
Call Stack
solve(3,5)
solve(2,5)
solve(0,5)
solve(3, 5) on segment [4, 7]
boundaries (endpoints + sorted cuts)
0
1
2
3
4
5
0
1
3
4
5
7
i
j
Call Stack
solve(1,3)
solve(0,3)
solve(0,5)
solve(1, 3) on segment [1, 4]
boundaries (endpoints + sorted cuts)
0
1
2
3
4
5
0
1
3
4
5
7
i
j
Call Stack
solve(0,1)
solve(0,4)
solve(0,5)
solve(0, 1) on segment [0, 1]
boundaries (endpoints + sorted cuts)
0
1
2
3
4
5
0
1
3
4
5
7
i
j
Call Stack
solve(1,4)
solve(0,4)
solve(0,5)
solve(1, 4) on segment [1, 5]
boundaries (endpoints + sorted cuts)
0
1
2
3
4
5
0
1
3
4
5
7
i
j
k
Call Stack
solve(1,3)
solve(0,3)
solve(0,4)
solve(0,5)
solve(1, 2) + solve(2, 3)
boundaries (endpoints + sorted cuts)
0
1
2
3
4
5
0
1
3
4
5
7
solve(0, 5) on segment [0, 7]
algo
master
.
io
Step:
Starting Minimum Cost to Cut a Stick (Recursion)
0 / 271
Input
Example 1
Example 2
Example 3
Example 4
Custom
n
=
7
,
cuts
=
[1, 3, 4, 5]
0 / 271
algo
master
.
io
Step:
Starting Minimum Cost to Cut a Stick (Recursion)