Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Cherry Pickup
Bookmark
Input
Example 1
Example 2
Example 3
Blocked Path
Mixed
Custom
grid
=
[[0,1,-1],[1,0,-1],[1,1,1]]
grid =
3x3
grid
dp[r1][r2]
0
1
X
1
0
X
1
1
1
two walkers collect cherries from corner to corner; shared cells count once
grid =
3x3
grid
dp[r1][r2]
0
1
X
1
0
X
1
1
1
two walkers collect cherries from corner to corner; shared cells count once
grid =
3x3
grid
dp[r1][r2]
0
1
X
1
0
X
1
1
1
0
-
-
-
-
-
-
-
-
0
0
1
1
2
2
dp[r1][r2] = best cherries with walker1 on row r1, walker2 on row r2
step t =
1
grid
dp[r1][r2]
0
1
X
1
0
X
1
1
1
-
-
-
-
-
-
-
-
-
0
0
1
1
2
2
step t = 1
: both walkers are on the diagonal row + col = 1
step t =
1
grid
dp[r1][r2]
0
1
X
1
0
X
1
1
1
1
2
-
-
-
-
-
-
-
0
0
1
1
2
2
best move
0
+
2
cherries =
2
step t =
1
grid
dp[r1][r2]
0
1
X
1
0
X
1
1
1
1
2
-
2
1
-
-
-
-
0
0
1
1
2
2
best move
0
+
1
cherry (shared) =
1
step t =
2
grid
dp[r1][r2]
0
1
X
1
0
X
1
1
1
-
-
-
-
2
-
-
-
-
0
0
1
1
2
2
best move
2
+
0
cherries (shared) =
2
step t =
2
grid
dp[r1][r2]
0
1
X
1
0
X
1
1
1
-
-
-
-
2
3
-
3
-
0
0
1
1
2
2
best move
2
+
1
cherry =
3
step t =
3
grid
dp[r1][r2]
0
1
X
1
0
X
1
1
1
-
-
-
-
-
-
-
-
-
0
0
1
1
2
2
step t = 3
: both walkers are on the diagonal row + col = 3
step t =
4
grid
dp[r1][r2]
0
1
X
1
0
X
1
1
1
-
-
-
-
-
-
-
-
-
0
0
1
1
2
2
step t = 4
: both walkers are on the diagonal row + col = 4
grid =
3x3
grid
dp[r1][r2]
0
1
X
1
0
X
1
1
1
-
-
-
-
-
-
-
-
5
0
0
1
1
2
2
max cherries =
5
algo
master
.
io
Step:
Two walkers go top-left to bottom-right at the same time, picking cherries. Shared cells count once
0 / 18
Input
Example 1
Example 2
Example 3
Blocked Path
Mixed
Custom
grid
=
[[0,1,-1],[1,0,-1],[1,1,1]]
0 / 18
algo
master
.
io
Step:
Two walkers go top-left to bottom-right at the same time, picking cherries. Shared cells count once