Skip to the code
cf.
+50 XP

#313 Cover Every Open Tile

hard

A robot vacuum game shows a floor plan grid as an array of strings. S is the start, E is the charging dock, . is open floor, and # is furniture. The robot moves up, down, left, or right.

Write countFullCleans(grid) that returns how many different routes go from S to E while stepping on every tile that isn't furniture exactly once (including S and E). The route must end when it reaches E.

Example 1

Input: grid = ["SE"]
Output: 1

Step from S straight onto E; both tiles are covered.

Example 2

Input: grid = ["S.","E."]
Output: 1

The only full route is right, down, left: S, the top-right tile, the bottom-right tile, then E.

Constraints

  • 1 <= grid.length * grid[0].length <= 20
  • Exactly one S and one E.
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).