Question bank › Dynamic Programming
Dsa Dynamic Programming Warm-up

Path to Treasure

You are given a 2D grid of size m x n, where each cell contains a positive integer representing the value of the cell. You want to start at the top-left corner and reach the bottom-right corner of the grid by moving only right or down. Your goal is to find the maximum value you can collect along your path. Write a function that calculates this maximum value. Input Format: - The first line contains two integers, m and n (1 <= m, n <= 100). - The next m lines each contain n space-separated integers, representing the grid values. Output Format: - A single integer representing the maximum value that can be collected. Example: Input: 3 3 1 2 3 4 5 6 7 8 9 Output: 21

Key concepts

dynamic_programminggridpathfinding

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.