Easy online java solution
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n    public int solve1(int i, int j, int arr[][], Integer memo1[][], int n, int d_limit) {\n        if(i<0||i>=n||j<0||j>=n||i>=j || (i==n-1 && j==n-1)) {\n            return 0 ; \n        }\n        if(memo1[i][j]!=null) {\n            return memo1[i][j] ; \n        }\n        int ans1 = arr[i][j] + solve1(i+1, j, arr, memo1, n, d_limit) ; \n        int ans2 = arr[i][j] +solve1(i+1, j-1, arr, memo1, n, d_limit-1) ; \n        int ans3 = arr[i][j] +solve1(i+1, j+1, arr, memo1, n, d_limit) ; \n        return memo1[i][j] = Math.max(ans1, Math.max(ans2, ans3)) ; \n    }\n    public int solve2(int i, int j, int arr[][], Integer memo2[][], int n, int d_limit) {\n        if(i<0||i>=n||j<0||j>=n||j>=i|| (i==n-1 && j==n-1)) {\n            return 0 ; \n        }\n        if(memo2[i][j]!=null) {\n            return memo2[i][j] ; \n        }\n        int ans1 = arr[i][j] +solve2(i, j+1, arr, memo2, n, d_limit) ; \n        int ans2 = arr[i][j] +solve2(i-1, j+1, arr, memo2, n, d_limit-1) ; \n        int ans3 = arr[i][j] +solve2(i+1, j+1, arr, memo2, n, d_limit) ; \n        return memo2[i][j] = Math.max(ans1, Math.max(ans2, ans3)) ; \n    }\n\n    public int maxCollectedFruits(int[][] arr) {\n        int n = arr.length ; \n        Integer memo1[][] = new Integer[n][n] ; \n        Integer memo2[][] = new Integer[n][n] ; \n        int d_limit = (int)Math.floor(n/2)-2 ; \n        int ans = 0 ; \n        for(int i=0; i<n; i++) {\n            ans += arr[i][i] ; \n            //arr[i][i] = -1 ;  \n        }\n        ans += solve1(0,n-1,arr, memo1, n, d_limit) ; \n        ans += solve2(n-1,0,arr, memo2, n, d_limit) ; \n        return ans ; \n        \n    }\n}\n```
['Java']