Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Maximum Number of Points with Cost
Bookmark
Brute Force
Left-Right DP
In-Place
Input
Example 1
Larger Matrix
Equal Values
Single Column
Custom
points
=
[[1,2,3],[1,5,1],[3,1,1]]
points
1
2
3
1
5
1
3
1
1
points
1
2
3
1
5
1
3
1
1
points
1
2
3
1
5
1
3
1
1
dp
1
2
3
newDp
which column of row 0 feeds column 0?
points
1
2
3
1
5
1
3
1
1
dp
1
2
3
newDp
2
newDp[0] = 1 + 1 = 2
points
1
2
3
1
5
1
3
1
1
dp
1
2
3
newDp
2
7
newDp[1] = 2 + 5 = 7
points
1
2
3
1
5
1
3
1
1
dp
1
2
3
newDp
2
7
4
newDp[2] = 3 + 1 = 4
points
1
2
3
1
5
1
3
1
1
dp
2
7
4
newDp
row 2: newDp is empty
points
1
2
3
1
5
1
3
1
1
dp
2
7
4
newDp
9
newDp[0] = 6 + 3 = 9
points
1
2
3
1
5
1
3
1
1
dp
2
7
4
newDp
9
8
newDp[1] = 7 + 1 = 8
points
1
2
3
1
5
1
3
1
1
dp
2
7
4
newDp
9
8
dp[1] - |1 - 2| = 6
points
1
2
3
1
5
1
3
1
1
dp
9
8
7
newDp
9
8
7
best total = 9
algo
master
.
io
Step:
Pick one cell per row. Switching columns between rows costs the distance moved
0 / 24
Input
Example 1
Larger Matrix
Equal Values
Single Column
Custom
points
=
[[1,2,3],[1,5,1],[3,1,1]]
0 / 24
algo
master
.
io
Step:
Pick one cell per row. Switching columns between rows costs the distance moved