Count Courier Routes Across a Grid of Partially Blocked Blocks
Last updated: November 29, 2026
Quick Overview
A courier moves only right or down across a city grid from the top-left to the bottom-right block, and some blocks are closed; return the number of distinct routes, modulo 1,000,000,007.
Uber
November 29, 20260
0
0 solved
A courier moves only right or down across a city grid from the top-left to the bottom-right block, and some blocks are closed; return the number of distinct routes, modulo 1,000,000,007.
A common Uber online assessment warm-up dressed in delivery terms. The grader checks a clean 2D DP with blocked cells, correct handling of a blocked start or goal, and the one-row space optimization.
What the Interviewer Expects
- Define ways[r][c] as the number of routes reaching each block
- Zero out blocked cells
- Handle blocked start or goal
- Use a single row array
- Apply the modulus
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
- What if the courier can also move diagonally down-right?
- Return the number of routes that pass through a specific restaurant block
- What if at most one closed block may be crossed?
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: grid of strings or lists where
'#'is closed and'.'is open. - Moves: right or down.
- Output: number of routes modulo
1e9 + 7; 0 if start or goal is closed....
High-Level Design
A route reaching block (r, c) arrives from above or from the left, so ways[r][c] = ways[r-1][c] + ways[r][c-1] for open blocks and 0 for closed ones. Processing rows top to bottom, a single array ...