- Given A 2 D Matrix M Where Each Cell M I J Contains Some Number Of Coins Find A Path To Collect Maximum Coins From Ce 1 (121.15 KiB) Viewed 19 times
Given a 2-D matrix M where each cell M[i][j] contains some number of coins, find a path to collect maximum coins from ce
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
Given a 2-D matrix M where each cell M[i][j] contains some number of coins, find a path to collect maximum coins from ce
Given a 2-D matrix M where each cell M[j] contains some number of coins, find a path to collect maximum coins from cell (x1, y1) to cell (x2, y2) in matrix M where x2 >= x1 and y2 >= y1. You can only travel one step right or one step down in each move. Write a function MaxCoinsPath(M,x1,y1,x1, y1) that accepts a matrix M, index (x1.y1) of the source cell and index (x2,y2) of the destination cell in matrix M. The function should return the maximum number of coins collected across all paths from source to destination. Sample Input 1 [[2.1.3.2.5].[3.5,2,4,6]. [7.6.1.3,2],[2.9.4,7,8],[1,4,5,11,3]] # Matrix M 2 (0,0) #Source (x1, y1) 3 (4,4) #Destination (x2.y2) Output 1 52 Explanation 2+3+7+6+9+4+7+11+3=52, which is maximum in all paths from (1,1) to (4,4).