Java Recursive+Memoization
Intuition
It looks similar to classic 2D dp grid question of finding paths as per given constraint
Here constraint is given on robot, means another state variab
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
1. It looks similar to classic 2D dp grid question of finding paths as per given constraint
2. Here constraint is given on robot, means another state variable has to be introduced
# Approach
<!-- Describe your approach to solving the problem. -->
1. Step-1 On every step if coins array has negative value, you have 2 options either consider that coins and move to next step or skip that coin then move to next step. Remeber you skip atmost 2 times for a particular path
2. Step-2 If coins array value is positive you take that coin and consider make of right and down direction
3. Step-3 Finally take maximum of step1 and step2 , save and return

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
O(m*n)

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
O(m*n)


# Code
```java []
class Solution {
    static int dp[][][];
    public int rec(int level, int j, int skip, int coins[][]){
        if(level == 0 && j == 0){
            System.out.println("here");
            int val = coins[0][0];
            if(skip > 0 && val < 0) return 0;
            System.out.println("this");
            return val;
        }
        if(level < 0 || j < 0) return (int)-1e9;
        if(dp[level][j][skip] != -3303) return dp[level][j][skip];
        int ans = (int) -1e9;
        if(coins[level][j] < 0 && skip > 0){
            ans = rec(level - 1, j, skip - 1, coins); //skip
            ans = Math.max(ans, rec(level, j - 1, skip - 1, coins)); //skip  
        }
        ans = Math.max(ans, coins[level][j] + rec(level - 1, j, skip, coins));
        ans = Math.max(ans, coins[level][j] + rec(level, j - 1, skip, coins));
        return dp[level][j][skip] = ans;
    }
    public int maximumAmount(int[][] coins) {
        // if(coins.length == 1 && coins[0].length == 1) return 0;
        dp = new int[coins.length][coins[0].length][3];
        for(int arr[][] : dp){
            for(int a[] : arr) Arrays.fill(a, -3303);
        }
        System.out.println((coins.length - 1)+"       "+(coins[0].length - 1));
        return rec(coins.length - 1, coins[0].length - 1, 2, coins);
    }
}
```
['Dynamic Programming', 'Memoization', 'Java']