Please tell me the error and how do you debug it?

hi @anmolaggarwal.432
kindly share the ques link…

hi @anmolaggarwal.432
u can simply do it like this -->

int minPathSum(vector<vector<int>>& grid) {
        int n = grid.size();
        int m = grid[0].size();
        int mat[n][m];
        mat[0][0] = grid[0][0];
        for(int j=1;j<m;j++){
            mat[0][j] = mat[0][j-1] + grid[0][j];
        }
        for(int i=1;i<n;i++){
            mat[i][0] = mat[i-1][0] + grid[i][0];
        }
        for(int i=1;i<n;i++){
            for(int j=1;j<m;j++){
                mat[i][j] = min(mat[i-1][j],mat[i][j-1])+grid[i][j];
            }
        }
        return mat[n-1][m-1];
    }

I know this but i want to identify problem in my code, not a new code Please tell me the error.

dp[0][0] = grid[0][0];

just remove this line… ur code will work fine…

@anmolaggarwal.432
I hope it’s clear now?

Yes sir it has been clear thanks for your help

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.