Dsa
Dynamic Programming
Easy
Forest Path Navigator
You are given a 2D grid representing a forest. Each cell in the grid has a positive integer value representing the number of trees in that cell. You need to find the maximum number of trees you can collect starting from the top-left corner and moving to the bottom-right corner. You can only move right or down. Return the maximum number of trees you can collect.
Input format:
- The first line contains two integers m and n (1 <= m, n <= 100) representing the number of rows and columns in the grid.
- The next m lines each contain n integers representing the number of trees in each cell.
Output format:
- Return a single integer representing the maximum number of trees collected.
Example:
Input:
3 3
1 2 3
0 5 0
4 0 6
Output:
12
Key concepts
dynamic_programminggrid_traversal
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now