FunctionRacerProblemsRace

Plow Every Cell

HardGridsPython, JavaScript, TypeScript, Java, C++

grid is a list of strings, one per row: S is the garage where a snowplow starts, E is the depot where it must finish, . is a snowy cell and # is a wall. The plow moves up, down, left or right one cell at a time, never enters a wall, and may not enter any cell a second time. A valid route starts at S, ends at E, and passes through every snowy cell exactly once. Return the number of valid routes. There is exactly one S and exactly one E.

Example 1

grid ["S..","...","..E"]
returns 2

Only the two snake patterns cover all nine cells: row by row, or column by column.

Example 2

grid ["S.","E."]
returns 1

The plow must clear the top-right and bottom-right cells before it can enter the depot: S, right, down, left.

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