Dsa
Dynamic Programming
Easy
Min Cost Path in Matrix
You are given a matrix of integers where each value represents the cost to move into that cell. You are tasked with finding the minimum cost to traverse from the top-left corner (0,0) to the bottom-right corner (m-1,n-1) of the matrix. You can only move right or down.
Input format:
- The first line contains two integers m and n (1 <= m, n <= 100) representing the dimensions of the matrix.
- The next m lines each contain n integers representing the costs.
Output format:
- Return a single integer representing the minimum cost to reach the bottom-right corner.
Example:
Input:
3 3
1 2 3
4 5 6
7 8 9
Output:
21
Key concepts
dynamic_programmingmatrix_traversal
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now