Dsa
Dynamic Programming
Warm-up
Minimum Distance for Delivery
In a city, delivery points are represented as a 2D grid where each cell represents the distance from the starting point. Your task is to find the minimum distance required to deliver goods from the top left corner (0, 0) to the bottom right corner (m-1, n-1) while only moving down or right.
Input Format:
- The first line contains an integer m (1 ≤ m ≤ 50), the number of rows.
- The second line contains an integer n (1 ≤ n ≤ 50), the number of columns.
- The following m lines each contain n space-separated integers representing the distances in the grid.
Output Format:
- Print a single integer: the minimum distance to reach the delivery point.
Example:
Input:
2
2
1 2
1 1
Output:
3
Key concepts
dynamic_programminggraphspathfinding
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