Count maximum path in grid

Last updated: April 3, 2026

Quick Overview

Given a grid represented by a 2D matrix, where each cell contains a non-negative integer representing the cost to enter that cell, count the maximum path sum from the top-left corner to the bottom-right corner of the grid, moving only down or right. The output should be a single integer representing the maximum path sum.

Waymo
Coding & Algorithms
Machine Learning Engineer
Waymo
April 3, 2026
Machine Learning Engineer
Technical Screen
Coding & Algorithms
Medium

9

2

1,172 solved


Given a grid represented by a 2D matrix, where each cell contains a non-negative integer representing the cost to enter that cell, count the maximum path sum from the top-left corner to the bottom-right corner of the grid, moving only down or right. The output should be a single integer representing the maximum path sum.

This coding problem is frequently asked during Technical Screen at Waymo. The interviewer is testing your ability to translate a problem into clean, working code while discussing time and space complexity. Waymo expects candidates to write production-quality code, not just solve the puzzle.

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
Tree structures and recursion
Graph algorithms and traversal
Common algorithm patterns (sliding window, two pointers, BFS/DFS)
Data structure selection and trade-offs
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
  • How would your solution change if the input was sorted?
  • What is the worst-case input for your solution?
  • Can you solve this in a single pass?
  • Can you solve this iteratively instead of recursively (or vice versa)?
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

This problem can be classified under dynamic programming because it requires us to build up a solution based on previously computed results. The goal is to find the maximum path sum from the top-left ...

Approach
  1. Initialize a 2D DP array: Create a DP array of the same dimensions as the grid to store maximum path sums up to each cell.
  2. Base Case: Set the starting point DP[0][0] equal to grid[0][0]....

Submit Your Answer
Markdown supported

Related Questions