Cheapest Monotone Route Across a Toll Cost Grid

Last updated: November 29, 2026

Quick Overview

Given an m x n grid of non-negative toll costs, return the minimum total cost of a route from the top-left to the bottom-right cell that only moves right or down, including both endpoint cells.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Given an m x n grid of non-negative toll costs, return the minimum total cost of a route from the top-left to the bottom-right cell that only moves right or down, including both endpoint cells.

An Easy Google phone screen DP problem, often used to see if candidates jump to Dijkstra unnecessarily. The interviewer wants the monotone-move observation that makes a simple DP enough and an O(n) space version.

What the Interviewer Expects
  • Explains why right-or-down moves make the grid a DAG
  • Writes cost[r][c] = grid[r][c] + min(top, left)
  • Handles the first row and column
  • Reduces memory to one row
  • Can reconstruct the route if asked
Key Topics to Cover
Dynamic Programming
Grid Paths
Rolling Arrays
DAG Shortest Path
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
  • Allow moves in all four directions: what algorithm now?
  • Return the actual route.
  • Costs can be negative; does the DP still work?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Input: grid, m x n non-negative ints.
  • Moves: right or down.
  • Output: the minimum sum of cells on a route from (0,0) to (m-1,n-1)....
High-Level Design

Because every move increases r + c, processing cells in row-major order sees every predecessor first. The best cost into a cell is its toll plus the cheaper of the cell above and the cell to the lef...


Submit Your Answer
Markdown supported