💥 Beats 100% on runtime [EXPLAINED]
IntuitionThe goal is to collect fruits in a 2D grid, where we can move in specific directions (up, down, left, right) to gather fruits and calculate the maximum
# Intuition
The goal is to collect fruits in a 2D grid, where we can move in specific directions (up, down, left, right) to gather fruits and calculate the maximum amount we can collect.

# Approach
Use dynamic programming to track the maximum fruits collected at each grid point; first, I fill the DP table while moving down, and then I update it while moving up, ensuring I take the best possible path at each step.

# Complexity
- Time complexity:
O(n * m), where n is the number of rows and m is the number of columns in the grid because we iterate through each grid cell multiple times (once for each direction).

- Space complexity:
O(n * m), as we use a 2D DP array to store the maximum collected fruits at each grid point.

# Code
```rust []
impl Solution {
    pub fn max_collected_fruits(f: Vec<Vec<i32>>) -> i64 {
        let n = f.len();
        let m = f[0].len();
        let mut dp = vec![vec![0; m]; n];

        dp[0][m - 1] = f[0][m - 1];
        for i in 1..n - 1 {
            for j in std::cmp::max(m - 1 - i, i + 1)..m {
                dp[i][j] = f[i][j];
                let mut x = 0;
                x = std::cmp::max(x, dp[i - 1][j]);
                if j > 0 {
                    x = std::cmp::max(x, dp[i - 1][j - 1]);
                }
                if j < m - 1 {
                    x = std::cmp::max(x, dp[i - 1][j + 1]);
                }
                dp[i][j] += x;
            }
        }

        dp[n - 1][0] = f[n - 1][0];
        for j in 1..m {
            for i in std::cmp::max(n - 1 - j, j + 1)..n {
                dp[i][j] = f[i][j];
                let mut x = 0;
                x = std::cmp::max(x, dp[i][j - 1]);
                if i > 0 {
                    x = std::cmp::max(x, dp[i - 1][j - 1]);
                }
                if i < n - 1 {
                    x = std::cmp::max(x, dp[i + 1][j - 1]);
                }
                dp[i][j] += x;
            }
        }

        let mut ans: i64 = 0; // Declare ans as i64 explicitly
        for i in 0..n {
            ans += f[i][i] as i64; // Convert to i64
        }
        ans += dp[n - 2][m - 1] as i64; // Convert to i64
        ans += dp[n - 1][m - 2] as i64; // Convert to i64

        ans
    }
}

```
['Array', 'Math', 'Dynamic Programming', 'Depth-First Search', 'Graph', 'Memoization', 'Matrix', 'Rust']