12. Gold Mine Problem
Last updated
Last updated
The problem can be found at the following link: Question Link
This problem can be solved using dynamic programming. I use a recursive approach to traverse through the possible paths and memoize the results using a 2D vector dp
to avoid recomputation.
The function traverse
calculates the maximum gold collected starting from each cell in the first column and moving to adjacent cells in the next columns [-1, 0 , 1]
(to right up , to right or to right down). The result is the maximum gold collected among all starting cells in the first column.
Time Complexity: O(n * m)
, where n is the number of rows and m is the number of columns in the grid.
Auxiliary Space Complexity: O(n * m)
, for the memoization table.
For discussions, questions, or doubts related to this solution, please visit our discussion section. We welcome your input and aim to foster a collaborative learning environment.
If you find this solution helpful, consider supporting us by giving a ⭐ star to the getlost01/gfg-potd repository.