Find maximum path in matrix
Last updated: November 28, 2025
Quick Overview
Given a matrix of integers, find the maximum path sum starting from any cell and moving to adjacent cells (up, down, left, right) without revisiting any cell. The function should return the maximum sum of values along the path. The input will be a 2D array of integers, and the output will be a single integer representing the maximum path sum.
OpenAI
November 28, 202510
4
1,281 solved
Given a matrix of integers, find the maximum path sum starting from any cell and moving to adjacent cells (up, down, left, right) without revisiting any cell. The function should return the maximum sum of values along the path. The input will be a 2D array of integers, and the output will be a single integer representing the maximum path sum.
OpenAI uses this problem in the Phone Screen to evaluate your algorithmic thinking. They expect you to discuss multiple approaches, analyze trade-offs between them, and implement the optimal solution with clean, readable code.
What the Interviewer Expects
- Recognize the underlying problem pattern (sliding window, two pointers, BFS/DFS, etc.)
- Discuss multiple approaches and trade-offs before coding
- Implement an optimal solution with clean, production-quality code
- Handle all edge cases including boundary conditions and invalid input
- Optimize both time and space complexity with clear justification
- Test your solution systematically with well-chosen examples
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Can you solve this in a single pass?
- What if the input doesn't fit in memory?
- What is the worst-case input for your solution?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Problem Analysis
The problem requires us to find the maximum path sum in a matrix by moving to adjacent cells (up, down, left, right) without revisiting any cell. This situation is best approached using Depth First Se...
Approach
- Initialize a variable to keep track of the maximum path sum.
- Create a memoization table (2D array) to store the maximum path sum starting from each cell.
- Iterate through each cell in the ...