FunctionRacerProblemsRace

Sealed Rooms

MediumGraphsPython, JavaScript, TypeScript, Java, C++

plan is a floor plan given as a list of strings of equal length: '#' is wall and '.' is floor. A room is a maximal group of floor cells in which every cell can reach every other by moving up, down, left or right through floor cells.

A room is sealed when none of its cells lies on the outer edge of the plan, that is, in the first or last row or in the first or last column. Return the number of sealed rooms; return 0 when there is none.

Example 1

plan ["#####","#...#","#.#.#","#...#","#####"]
returns 1

The eight floor cells form a ring around the central wall; none of them touches the edge, so the ring is one sealed room.

Example 2

plan ["#####","#.#.#","#####"]
returns 2

The two floor cells are separated by a wall and neither touches the edge: two sealed rooms.

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 Graphs problems