Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Cherry Pickup
Bookmark
Greedy
3D DP
Memoization
Input
Example 1
Example 2
Example 3
Blocked Path
Mixed
Custom
grid
=
[[0,1,-1],[1,0,-1],[1,1,1]]
grid
0
1
X
1
0
X
1
1
1
trip 1 = -
trip 2 = -
total = -
grid
0
1
X
1
0
X
1
1
1
trip 1 = -
trip 2 = -
total = -
grid
0
1
X
1
0
X
1
1
1
dp for this trip
0
1
-
1
1
-
2
3
4
trip 1: dp[i][j] = best cherries reaching that cell
trip 1 = -
trip 2 = -
total = -
grid
0
1
X
1
0
X
1
1
1
dp for this trip
0
1
-
1
1
-
2
3
4
trip 1 reaches the far corner with 4
trip 1 = -
trip 2 = -
total = -
grid
0
1
X
1
0
X
1
1
1
dp for this trip
0
1
-
1
1
-
2
3
4
trip 1 reaches the far corner with 4
trip 1 = -
trip 2 = -
total = -
grid
0
1
X
0
0
X
0
0
0
dp for this trip
0
1
-
1
1
-
2
3
4
trip 1 took 4 cherries
trip 1 = 4
trip 2 = -
total = -
grid
0
1
X
0
0
X
0
0
0
dp for this trip
0
1
-
0
1
-
0
1
1
trip 2 runs on the cleared board
trip 1 = 4
trip 2 = -
total = -
grid
0
1
X
0
0
X
0
0
0
dp for this trip
0
1
-
0
1
-
0
1
1
trip 2 finds 1 cherry
trip 1 = 4
trip 2 = -
total = -
grid
0
1
X
0
0
X
0
0
0
dp for this trip
0
1
-
0
1
-
0
1
1
4 + 1 = 5
trip 1 = 4
trip 2 = 1
total = 5
algo
master
.
io
Step:
Optimise one trip, clear what it picked, then optimise a second trip on what is left
0 / 7
Input
Example 1
Example 2
Example 3
Blocked Path
Mixed
Custom
grid
=
[[0,1,-1],[1,0,-1],[1,1,1]]
0 / 7
algo
master
.
io
Step:
Optimise one trip, clear what it picked, then optimise a second trip on what is left