Skip to the code
cf.
+10 XP

#504 Routes Around Blocked Tiles

easy

A tile-based level editor stores a level as an array of strings, board, where "." is an open tile and "#" is a wall. A character starts on the top-left tile and wants to reach the bottom-right tile, moving one tile right or down at a time and never onto a wall.

Write countRoutes(board) that returns the number of different routes. If the start or the end is a wall, return 0.

Example 1

Input: board = ["...",".#.","..."]
Output: 2

Go around the wall in the middle: along the top and right, or along the left and bottom.

Example 2

Input: board = ["..","#."]
Output: 1

The only route is right, then down.

Constraints

  • 1 <= board.length, board[0].length <= 16
  • Every row has the same length and contains only . and #.
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).