Simple and Clean Solution || (Using Memoization) ✅✅
Code\ncpp []\nclass Solution {\npublic:\n    int dx1[4]={1,1,1};\n    int dy1[4]={-1,0,1};\n    int dx2[4]={1,0,-1};\n    int dy2[4]={1,1,1};\n    int helper(ve
# Code\n```cpp []\nclass Solution {\npublic:\n    int dx1[4]={1,1,1};\n    int dy1[4]={-1,0,1};\n    int dx2[4]={1,0,-1};\n    int dy2[4]={1,1,1};\n    int helper(vector<vector<int>> & fruits,int x,int y,int n,int label,vector<vector<int>> &dp){\n        if(x==(n-1) && y==(n-1)){\n            return 0;\n        }\n        if(dp[x][y]!=-1){\n            return dp[x][y];\n        }  \n        int ans=0;\n        for(int k=0;k<3;k++){\n            int nx=0;\n            int ny=0;\n            if(label==1){\n                nx=x+dx1[k];\n                ny=y+dy1[k];\n            }\n            if(label==2){\n                nx=x+dx2[k];\n                ny=y+dy2[k];\n            }\n            if(nx<n && ny<n && nx>=0 && ny>=0){\n                if(label==1 && ny<=nx && !(nx==(n-1) && ny==(n-1))){\n                    continue;\n                }\n                if(label==2 && nx<=ny && !(nx==(n-1) && ny==(n-1))){\n                    continue;\n                }\n                ans=max(ans,fruits[x][y]+helper(fruits,nx,ny,n,label,dp));\n            }\n        }\n        return dp[x][y]=ans;\n    }\n    int maxCollectedFruits(vector<vector<int>>& fruits) {\n        int n=fruits.size();\n        vector<vector<int>> dp(n,vector<int>(n,-1));\n        int ans=0;\n        for(int i=0;i<n;i++){\n            ans+=fruits[i][i];\n        }\n        ans+=helper(fruits,0,n-1,n,1,dp);\n        ans+=helper(fruits,n-1,0,n,2,dp);\n        return ans;\n    }\n};\n```
['Dynamic Programming', 'Memoization', 'C++']