Cheapest Route for a Maintenance Cart Across a Data Center Floor

Last updated: November 29, 2026

Quick Overview

A grid gives the cost to cross each floor tile of a data center hall. Starting at the top-left tile and moving only right or down, return the minimum total cost to reach the bottom-right tile.

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

0

0

0 solved


A grid gives the cost to cross each floor tile of a data center hall. Starting at the top-left tile and moving only right or down, return the minimum total cost to reach the bottom-right tile.

Used as a warm-up in Meta phone screens before a harder second question. The interviewer checks that you can define a DP state precisely, handle the first row and column, and reduce memory to one row without bugs.

What the Interviewer Expects
  • Recognize optimal substructure from the right/down move constraint
  • Handle the first row and first column boundaries
  • Fill in a single pass in row-major order
  • Reduce to O(columns) memory
  • Mention why Dijkstra is unnecessary here
Key Topics to Cover
Grid dynamic programming
Rolling array
Boundary handling
Path cost minimization
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 you also return the path itself?
  • What changes if the cart may move in all four directions?
  • What if some tiles are impassable?
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 is an r x c grid of non-negative integers with at least one cell. The cart starts on (0, 0) and must end on (r-1, c-1), paying the cost of every tile it stands on, including both endpoints...

High-Level Design

Because moves only go right or down, any path into cell (i, j) arrives from (i-1, j) or (i, j-1). So the cheapest cost to reach a cell is its own cost plus the cheaper of those two. Cells in the...


Submit Your Answer
Markdown supported