Question bank › Dynamic Programming
Dsa Dynamic Programming Warm-up

Longest Path in a City

You live in a city represented as a 2D grid where each cell contains a non-negative integer representing the cost of moving through that cell. Your goal is to find the minimum cost to reach the bottom-right corner from the top-left corner if you can only move right or down. 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 costs in the grid. Output Format: - Print a single integer: the minimum cost to reach the bottom-right corner. Example: Input: 2 3 1 2 3 4 5 6 Output: 12

Key concepts

dynamic_programminggraphsgrids

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
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.