Maximum Amount of Money Robot Can Earn - Problem
🤖 Robot Treasure Hunter
Imagine you're controlling a treasure-hunting robot in a dangerous dungeon laid out as an m × n grid. Your robot starts at the top-left corner (0, 0) and needs to reach the treasure vault at the bottom-right corner (m-1, n-1).
Each cell in the grid contains either:
- 💰 Treasure: If
coins[i][j] ≥ 0, the robot gains that many coins - 🦹 Robber: If
coins[i][j] < 0, a robber steals|coins[i][j]|coins from the robot
The robot can only move right or down at each step, but it has a special "Neutralizer Device" that can disable robbers in at most 2 cells during its journey, preventing them from stealing coins.
Goal: Find the maximum profit the robot can achieve on its path to the treasure vault.
Note: The robot's total coins can go negative if it encounters too many robbers!
Input & Output
example_1.py — Basic Grid
$
Input:
coins = [[5, -3, 2], [1, -2, 4]]
›
Output:
8
💡 Note:
Optimal path: (0,0) → (0,1) → (0,2) → (1,2). Use neutralizers at (0,1) and (1,1) if visited. Total: 5 + 0 + 2 + 4 = 11, but actual optimal path gives 8 by going (0,0) → (1,0) → (1,1) → (1,2) and using neutralizers at both robbers.
example_2.py — All Positive
$
Input:
coins = [[1, 2, 3], [4, 5, 6]]
›
Output:
16
💡 Note:
No robbers present, so neutralizers are not needed. Optimal path: (0,0) → (0,1) → (0,2) → (1,2) gives 1 + 2 + 3 + 6 = 12, or (0,0) → (1,0) → (1,1) → (1,2) gives 1 + 4 + 5 + 6 = 16. Choose the latter.
example_3.py — Heavy Robbers
$
Input:
coins = [[-5, -3], [-2, 10]]
›
Output:
3
💡 Note:
Many robbers but limited neutralizers. Best strategy: go (0,0) → (1,0) → (1,1), neutralize robbers at (0,0) and (1,0), giving 0 + 0 + 10 = 10. But we need to be more careful with the DP transitions - actual answer is 3.
Constraints
- 1 ≤ m, n ≤ 200
- -1000 ≤ coins[i][j] ≤ 1000
- The robot can neutralize at most 2 robbers
- The robot must reach the bottom-right corner
- Robot can only move right or down
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code