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?

AnswerBot
4mo
The Minimum Path Sum Problem involves finding the minimum sum of costs along a path from the top-left to the bottom-right of a grid.
Use dynamic programming to calculate the minimum path sum by conside...read more
Help your peers!
Add answer anonymously...
Amazon Software Developer interview questions & answers
A Software Developer was asked 1mo agoQ. What is HTML?
A Software Developer was asked 1mo agoQ. What is MySQL?
A Software Developer was asked 2mo agoQ. Given two strings s and t, return true if they are equal when both are typed int...read more
Popular interview questions of Software Developer
A Software Developer was asked 1mo agoQ1. What is HTML?
A Software Developer was asked 1mo agoQ2. What is MySQL?
A Software Developer was asked 2mo agoQ3. What is the system design for the cart feature in an e-commerce website?
Top HR questions asked in Amazon Software Developer
A Software Developer was asked 1mo agoQ1. Tell me about a time you had to get to the root cause of a problem
A Software Developer was asked 5mo agoQ2. What are the short-term and long-term goals for the team or organization?
A Software Developer was asked 5mo agoQ3. Why do you want to work at Amazon?
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

