C++ || Dynamic Programming || Memoization || Simple Code
Complexity

Time complexity: O (M * N * 3)


Space complexity: O (M * N * 3)

Code
# Complexity
- Time complexity: O (M * N * 3)

- Space complexity: O (M * N * 3)

# Code
```cpp []
class Solution {
public:
    
    int fun(int i , int j, int pass, vector<vector<int>>& coins, vector<vector<vector<int>>>& dp)
    {

        if(i == 0 && j == 0)
        {
            return (coins[i][j] >= 0) ? coins[i][j] : (pass >= 1) ? 0 : coins[i][j]; 
        }

        if(i < 0 || j < 0) return -1e8;

        if(dp[i][j][pass] != 1e9 ) return dp[i][j][pass];

        int one , two;

        if(coins[i][j] >= 0){
            one = coins[i][j] + fun(i - 1, j, pass, coins, dp);
            two = coins[i][j] + fun(i, j - 1, pass, coins, dp);
        }else{
            one = INT_MIN, two = INT_MIN;
            if(pass >= 1){
                one = fun(i - 1, j, pass - 1, coins, dp);
                two = fun(i , j - 1, pass - 1, coins, dp);
            }
            one = max(one, fun(i - 1, j, pass, coins, dp) - abs(coins[i][j]));
            two = max(two, fun(i, j - 1, pass, coins, dp) - abs(coins[i][j]));
        }

        return dp[i][j][pass] = max(one, two);
        
    }
    
    int maximumAmount(vector<vector<int>>& coins) 
    {
        
        int m = coins.size(), n = coins[0].size(), ans;
        
        vector<vector<vector<int>>> dp(m, vector<vector<int>>(n, vector<int>(3, 1e9)));
        
        ans = fun(m - 1, n - 1, 2, coins, dp);
        
        return ans;
        
    }
};
```
['Dynamic Programming', 'Memoization', 'C++']