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.
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
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- 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 ProblemsSample Answer
Requirements
- Input:
gridof 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...