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
Coding & Algorithms
Machine Learning Engineer
OpenAI
November 28, 2025
Machine Learning Engineer
Phone Screen
Coding & Algorithms
Medium

10

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
Data structure selection and trade-offs
Time and space complexity analysis
Edge cases and input validation
Sorting and searching
Tree structures and recursion
Dynamic programming and memoization
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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
  1. Initialize a variable to keep track of the maximum path sum.
  2. Create a memoization table (2D array) to store the maximum path sum starting from each cell.
  3. Iterate through each cell in the ...

Submit Your Answer
Markdown supported

Related Questions