Super Easy and least lines of code
IntuitionTry All possible cases to reach the end points with given constraints and movesApproachUsed memoization after running recursive solutionComplexity
Time
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Try All possible cases to reach the end points with given constraints and moves
# Approach
<!-- Describe your approach to solving the problem. -->
Used memoization after running recursive solution

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

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

# Code
```cpp []
class Solution {
public:
    int maximumAmount(vector<vector<int>>& coins) {

        int n = coins.size(), m = coins[0].size();
        vector<vector<vector<int>>> dp(n+1, vector<vector<int>>(m+1, vector<int>(3, -1)));

        function<int(int, int, int)> f = [&](int i, int j, int rem) -> int{
            
            if(i == n-1 && j == m-1) {
                if(coins[i][j] < 0 && rem > 0) return 0;
                return coins[i][j];
            }
            if(i >= n || j >= m) return -1e9;

            if(dp[i][j][rem] != -1) return dp[i][j][rem];
            
            int mx = coins[i][j] + max(f(i+1, j, rem), f(i, j+1, rem));
            
            if(coins[i][j] < 0 && rem > 0) {
                mx = max({mx, f(i+1, j, rem-1), f(i, j+1, rem-1)});
            }
            return dp[i][j][rem] = mx;
        };
        int ans = f(0, 0, 2);
        return ans;
    }
};
```
['Dynamic Programming', 'Memoization', 'C++']