Matrix Maximum Path Sum Problem

Given an N*M matrix filled with integer numbers, your task is to find the maximum path sum starting from any cell in the first row and ending at any cell in the last row. You can move downward, diagonally down to the left, or diagonally down to the right from any cell.

Example:

Input:
T = 1
N = 3, M = 3
Matrix: [[3, 2, 1], [5, 10, 7], [9, 6, 8]]
Output:
18
Explanation:

The path with the maximum sum is 3 -> 10 -> 9, which results in a sum of 18.

Constraints:

  • 1 ≤ T ≤ 50
  • 1 ≤ N ≤ 100
  • 1 ≤ M ≤ 100
  • -10^4 ≤ matrix[i][j] ≤ 10^4
Input:

The input will follow this format:

```
T
N M
Matrix rows
```
Output:

For each test case, you should output the maximum sum obtainable on a new line.

Note:

You are not required to print anything. The code should simply return the result.

AnswerBot
29d

Find the maximum path sum in a matrix from the first to the last row with specific movement rules.

  • Use dynamic programming to store maximum sums at each cell.

  • Start from the first row and iterate downwa...read more

Help your peers!
Select
Add answer anonymously...

PhonePe Software Developer interview questions & answers

A Software Developer was asked 6mo agoQ. Why do you want to join?
A Software Developer was asked 8mo agoQ. Given a graph, write a function to perform a Breadth-First Search (BFS) traversa...read more
A Software Developer was asked Q. Insertion in AVL Tree Problem Statement You are required to implement an AVL Tre...read more

Popular interview questions of Software Developer

A Software Developer was asked 6mo agoQ1. Why do you want to join?
A Software Developer was asked Q2. Insertion in AVL Tree Problem Statement You are required to implement an AVL Tre...read more
A Software Developer was asked Q3. Unlock the Briefcase Problem Statement You have a briefcase secured by a lock wi...read more
PhonePe Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits