Warehouse Robot Routes

Easy · 2-D & String DP · about 15 min

A delivery robot starts in the top-left cell of a warehouse floor and must reach the bottom-right cell. It can only move one cell right or one cell down at a time. The floor is grid: 0 is an open cell and 1 is a shelf the robot cannot enter.

Return the number of different routes. If the start or the finish is a shelf, the answer is 0.

  • 1 <= rows, cols <= 16.

Example:

count_open_routes([[0, 0, 0], [0, 1, 0], [0, 0, 0]]) → 2 (around the shelf on either side)

Hints

  • The robot can only arrive at a cell from above or from the left.
  • A shelf cell has no routes. The start cell has one route if it is open.
  • Treat cells outside the grid as 0 routes, so the first row and column need no special rule.

Learn the pattern first: the 2-D & String DP lesson.

More 2-D & String DP problems