Gamified challenge · Grid dynamic programming
grid[r][c] is 0 for an open tile and 1 for a rock. A hiker starts on the top-left tile and must reach the bottom-right tile, moving only right or down, one tile at a time, never onto a rock.
Write paths(grid) that returns how many different routes there are. For [[0, 0, 0], [0, 1, 0], [0, 0, 0]] the answer is 2: around the rock along the top, or along the left. If the start or the exit is a rock, the answer is 0.
The grid has at least one tile and at most 16 rows and 16 columns, so the answer fits in an int.
This game is part of the paid plans. Sign in, then pick a plan to write your answer, watch it play out, and step through the algorithm with its guide.
Sign in with Google