FunctionRacerProblemsRace

Paths Around Rocks

MediumGridsPython, JavaScript, TypeScript, Java, C++

grid holds 0 for an open cell and 1 for a rock. A hiker starts in the top-left cell and wants to reach the bottom-right cell, moving one cell right or one cell down at a time and never entering a rock. Return the number of different routes. If the start or the goal is a rock, or no route exists, return 0.

Example 1

grid [[0,0,0],[0,1,0],[0,0,0]]
returns 2

With the centre blocked, the hiker can go around it along the top and right edges or along the left and bottom edges.

Example 2

grid [[0,0],[0,0]]
returns 2

Right then down, or down then right.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Grids problems