Count Monotone Routes for a Warehouse Robot Around Blocked Shelves

Last updated: November 29, 2026

Quick Overview

A robot starts at the top-left of an m x n warehouse grid and may only move right or down; given a grid where 1 marks a blocked shelf, return the number of distinct routes to the bottom-right cell.

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

0

0

0 solved


A robot starts at the top-left of an m x n warehouse grid and may only move right or down; given a grid where 1 marks a blocked shelf, return the number of distinct routes to the bottom-right cell.

A Google phone screen DP problem in a fulfillment robotics framing. The interviewer checks the base cases (a blocked start or goal, a blocked first row) and whether you compress the table to one row.

What the Interviewer Expects
  • Writes the recurrence ways[r][c] = ways[r-1][c] + ways[r][c-1] for open cells
  • Sets ways to 0 on blocked cells, including the start
  • Initializes the first row and column carefully when a block appears
  • Uses O(n) space
  • Mentions modular arithmetic or big integers for large grids
Key Topics to Cover
Dynamic Programming
Grid Paths
Rolling Arrays
Counting
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
  • Return the count modulo 1e9+7 for a 1000 x 1000 grid.
  • Allow the robot to also move diagonally down-right.
  • Return one valid route, or report that none exists, in O(mn).
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 of 0 (open) and 1 (blocked).
  • Moves: right or down only.
  • Output: number of routes from (0,0) to (m-1,n-1); 0 if either end is blocked....
High-Level Design

The last move into a cell came from above or from the left, so the counts add. A blocked cell has 0 ways, which also stops everything past a block in the first row or column from being reachable, with...


Submit Your Answer
Markdown supported