Loading
Loading
A bike courier crosses a district laid out as a grid of blocks. She starts at the top-left block and must deliver to the bottom-right block. To keep to one-way cycle lanes, every move goes either one block east (right) or one block south (down).
Some blocks are closed for roadworks: grid[r][c] = 1 means closed, 0 means open. Return how many different routes reach the destination using only open blocks. If the start or the destination is closed, there are no routes.
grid = [[0, 0, 0], [0, 1, 0], [0, 0, 0]]row 0: 1 1 1only reachable by going eastrow 1: 1 0 1the closed centre contributes nothingrow 2: 1 1 2each cell = from above + from the left2Sign in to keep a note here. It is free, and nobody else can see it.
Sign inExample 1
| 0 | 0 | 0 | 0 |
|---|---|---|---|
| 1 | 0 | 1 | 0 |
| 2 | 0 | 0 | 0 |
With the centre closed, only the route along the top and the route down the left side remain.
Example 2
Sign in to open hints.
Struggling is where the learning happens. Open this once you have genuinely tried, or once the hints have run out.
O(rows × cols) time · O(cols) space
Input. Run your code to watch it work on this input, one line at a time.
| 0 | 0 | 0 | 0 |
|---|---|---|---|
| 1 | 0 | 1 | 0 |
| 2 | 0 | 0 | 0 |
Running code is turned off on this deployment. You can still read the problem, write code, use hints and the visualizer.
Tab moves focus out of the editor. Press Ctrl+M to let Tab indent instead.
No results yet
Run your code against the sample tests, or submit to run the full suite.
| 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|
| 1 | 0 | 0 | 1 | 0 |
| 2 | 1 | 0 | 0 | 0 |
Three routes steer around the two closed blocks.