ORIGINAL CODING QUESTION
Routes through a blocked grid
Start at the top-left and move only right or down to the bottom-right. Zero cells are open and one cells blocked. Count routes modulo 1,000,000,007; blocked endpoints yield zero.
Original exercise · medium. Editorial role relevance does not imply a company has asked this question.
Input and output
rows cols, then rows×cols cell values in row-major order. Print one integer.
Constraints
1 ≤ rows,cols ≤ 12; each cell is 0 or 1; adjacency uses four sides, not diagonals.
Example 1
Input
2 2 0 0 0 0
Output
2
Two right/down routes exist.
Example 2
Input
2 2 0 1 1 0
Output
0
Both paths are blocked.
Explain your approach
Explain your time and auxiliary space complexity. Which input makes your algorithm work hardest?
Private grading inputs, expected outputs and canonical reference implementations are withheld. Authored expected outputs were cross-checked with independent reference oracles; compiler/runtime behavior still needs a verified execution provider.
Hint 1
A route into a cell arrives from above or left.
Hint 2
Blocked cells contribute zero routes.
Hint 3
Seed an open starting cell with one route.
Practice this question
Save your work privately, explain decisions and return to your revision queue.
Open practice workspaceBrowse the question library →