#3418
Maximum Amount of Money Robot Can Earn
expert · 1130 · lc medium +32 · 29.5% accepted · 137 likes · top 7%
Description
You are given an m x n grid. A robot starts at (0, 0) and must reach (m - 1, n - 1), moving only right or down.
Each cell coins[i][j] holds a value:
- If coins[i][j] >= 0, the robot gains that many coins.
- If coins[i][j] < 0, a robber steals abs(coins[i][j]) coins from the robot.
The robot can neutralize robbers in at most 2 cells on its path, preventing any coin theft in those cells.
The robot's coin total may go negative.
Return the maximum profit the robot can achieve.
Code
1
2
3