you give 0indexed m x n integer matrix grid consist distinct integer 0 m n 1 you matrix cell cell row that cell x y x m 1 cell x 1 0 x 1 1 x 1 n 1 note possible cell roweach possible cost give 0indexed 2d array movecost size m n x n movecostij cost move cell value cell column j row the cost move cell row grid ignoredthe cost path grid sum value cell visit plus sum cost move return minimum cost path start cell row end cell row Example 1input grid 534021 moveCost 9815101218624143output 17explanation the path minimum possible cost path 5 0 1 the sum value cell visit 5 0 1 6 the cost move 5 0 3 the cost move 0 1 8so total cost path 6 3 8 17example 2input grid 512403 movecost 121015202382171811391025532output 6explanation the path minimum possible cost path 2 3 the sum value cell visit 2 3 5 the cost move 2 3 1so total cost path 5 1 6 Constraintsm gridlengthn gridilength2 m n 50grid consist distinct integer 0 m n 1movecostlength m nmovecostilength n1 movecostij 100