• Tutorials
  • DSA
  • Data Science
  • Web Tech
  • Courses
August 14, 2024 |570 Views

SDE Sheet - Min Cost Path

Description
Discussion

This video is part of the Dynamic Programming section under GFG SDE Sheet.

Given a n x n matrix of positive integers. There are only three possible moves from a cell mat[r][c].

  1. mat[r+1] [c]
  2. mat[r+1] [c-1]
  3. mat [r+1] [c+1]

Starting from any column in row 0 return the largest sum of any of the paths up to row n -1. Return the highest maximum path sum.

Note : We can start from any column in zeroth row and can end at any column in (n-1)th row.

Examples :

Input: n = 2, mat = [[348, 391],[618, 193]] Output: 1009 Explaination: The best path is 391 -> 618. It gives the sum = 1009.

Try it out before watching the implementation of the problem in the video. We recommend watching the video, even if you can solve the problem. You may discover something new. All the best!!!

Do check out:-
Problem: https://www.geeksforgeeks.org/problems/path-in-matrix3805/1
SDE Sheet Link: https://www.geeksforgeeks.org/sde-sheet-a-complete-guide-for-sde-preparation/
Article Link: https://www.geeksforgeeks.org/min-cost-path-dp-6/?ref=gcse