09. Minimum Points To Reach Destination
The problem can be found at the following link: Question Link
My Approach
We will use dynamic programming to solve this problem.
We initialize a 2D DP array
dp
of sizem x n
, wheredp[i][j]
represents the minimum points required to reach the destination starting from(i, j)
.We start from the bottom-right corner and move upwards and leftwards, calculating the minimum points required at each cell to reach the destination.
At each cell
(i, j)
, we calculatedp[i][j]
using the formula:dp[i][j] = max(1, min(dp[i+1][j], dp[i][j+1]) - points[i][j])
.We return
dp[0][0]
which represents the minimum points required to reach the destination starting from the top-left corner.
Time and Auxiliary Space Complexity
Time Complexity: The time complexity of this approach is
O(m * n)
, where m is the number of rows and n is the number of columns in thepoints
matrix.Auxiliary Space Complexity: The auxiliary space complexity is
O(m * n)
due to the dynamic programming matrixdp
.
Code (C++)
Contribution and Support
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.
Last updated