Minimum Path Sum Problem Statement
Consider a 2-dimensional grid 'GRID' with 'N' rows and 'M' columns in Ninjaland. Each cell in the grid has an associated cost. The goal is to determine the minimum path sum from the top-left to the bottom-right, moving only down or right.
Explanation:
Find a path from top-left (0, 0) to bottom-right ('N'-1, 'M'-1) that minimizes the sum of costs along the path.
Input:
The first line contains an integer 'T' denoting the number of test cases.
The first line of each test case contains two space-separated integers 'N' and 'M', indicating the grid's dimensions.
The next 'N' lines each contain 'M' space-separated integers, representing the costs for that row.
Output:
For each test case, output the minimum path sum from the top-left to the bottom-right corner of the grid.
Example:
Example input and output have been omitted for brevity. Please refer to test cases to validate functionality.
Constraints:
1 <= T <= 100
1 <= N, M <= 102
1 <= GRID[i][j] <= 105
- Time limit: 1 sec
Note:
You need to implement the function to compute the result, printing is managed internally.
Follow Up:
Can you solve this problem with an O(1) space complexity solution?
Be the first one to answer
Add answer anonymously...
Top Amazon Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in Amazon Software Developer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app