Easy Java Solution (✨Beats 100%) (Memoization)
IntuitionThe robot can move only down or right at each step, and the grid cells contain either a positive value (coins gained) or a negative value (coins stolen
### Intuition
The robot can move only down or right at each step, and the grid cells contain either a positive value (coins gained) or a negative value (coins stolen by robbers). **The robot can neutralize robbers in up to two cells** during its journey. This means we need to compute the maximum profit by considering both paths, as well as the use of neutralizing robbers, to ensure we make the best possible decisions.

### Approach
  
1. **Base Case**: If we reach the bottom-right corner `(m-1, n-1)`, we check if the current cell has a negative value (robber). If the robot still has neutralizations left, we neutralize the robber; otherwise, the robot loses coins equal to the absolute value of the cell.

2. **Recursive Case**: At each cell, we explore two possible moves: one to the cell below `(i+1, j)` and one to the cell to the right `(i, j+1)`. We choose the maximum profit from both moves.
3. **Negative Values**: If the cell has negative values, we should minimize the loss by using neutralize power. Either we can use our power at that point or save it for future. If we use it, save its case in `use` variable and wasting case in `waste` variable
4. **Max Value**: Now at the end, return the maximum possible value of all three cases.

3. **Dynamic Programming (DP) Setup**: We define a 3D DP array, `dp[i][j][n]`, where `i` and `j` represent the current cell in the grid, and `n` represents the number of neutralizations left. The value at `dp[i][j][n]` represents the maximum profit the robot can gain starting from cell `(i, j)` with `n` neutralizations remaining.

4. **Memoization**: To avoid recalculating the same state multiple times, we use memoization to store the results of subproblems in the `dp` array.

5. **Return Result**: Finally, the result of the problem is stored in `dp[0][0][2]`, which gives the maximum profit starting from the top-left corner with 2 neutralizations.

### Complexity
- **Time Complexity**: The time complexity is \(O(m \times n \times 3)\), where \(m\) is the number of rows and \(n\) is the number of columns in the grid. The factor of 3 accounts for the 3 possible states of neutralizations (0, 1, or 2) at each grid cell.
  
- **Space Complexity**: The space complexity is also \(O(m \times n \times 3)\) due to the 3D DP array storing the results of subproblems.

# Code Logic (No-DP)

```java []
class Solution {
    private int helper(int [][]array, int i, int j, int n){
        //if we go out of the grid
        if(i>=array.length||j>=array[0].length){
            return Integer.MIN_VALUE;
        }
        //if we reach at the end
        if(i==array.length-1&&j==array[0].length-1){
            //if we have negative value at the end
            if(array[i][j]<0){
                //if we have neutralize power, use it, else return the negative value
                return n>0?0:array[i][j];
            }else{
                return array[i][j];
            }
        }
        int value=array[i][j];
        // further calls maximum solution (not handling curr values as of now)
        int max=Math.max(helper(array,i+1,j,n),helper(array,i,j+1,n));
        int use=Integer.MIN_VALUE;
        int waste=Integer.MIN_VALUE;
        //if we have negative value at curr idx
        if(value<0){
            //if we have left with neutralize power
            if(n>0){
                //either use it
                use=Math.max(helper(array,i+1,j,n-1),helper(array,i,j+1,n-1));
            }
            // or waste it
            waste=max-Math.abs(value);
        }
        // max+value is the case when we have positive value, we need to add it.
        //find max of all three conditions
        return Math.max(max+value,Math.max(use,waste));
    }
    public int maximumAmount(int[][] coins) {
        return helper(coins,0,0,2);
    }
}

// 0  1  -1
// 1  -2  3
// 2  -3  4

// [4,-16,1,-11]
// [6,18,-17,14]
// [16,-10,9,3]
// [-11,17,0,-11]
```

# Code (Submitted)
```java []
class Solution {
    private int helper(int [][]array, int i, int j, int n,Integer[][][] dp){
        if(i>=array.length||j>=array[0].length){
            return Integer.MIN_VALUE;
        }
        if(i==array.length-1&&j==array[0].length-1){
            if(array[i][j]<0){
                return n>0?0:array[i][j];
            }else{
                return array[i][j];
            }
        }
        if (dp[i][j][n] != null) {
            return dp[i][j][n];
        }
        int value=array[i][j];
        int max=Math.max(helper(array,i+1,j,n,dp),helper(array,i,j+1,n,dp));

        int use=Integer.MIN_VALUE;
        int waste=Integer.MIN_VALUE;
        if(value<0){
            if(n>0){
                use=Math.max(helper(array,i+1,j,n-1,dp),helper(array,i,j+1,n-1,dp));
            }
            waste=max-Math.abs(value);
        }
        dp[i][j][n]= Math.max(max+value,Math.max(use,waste));
        return dp[i][j][n];
    }
    public int maximumAmount(int[][] array) {
        Integer[][][] dp = new Integer[array.length][array[0].length][3]; // Memoization
        return helper(array,0,0,2,dp);
    }
}
```
['Dynamic Programming', 'Recursion', 'Memoization', 'Matrix', 'Java']