Sealed Rooms
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
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
The two floor cells are separated by a wall and neither touches the edge: two sealed rooms.
Constraints
1 <= len(plan) <= 101 <= len(plan[i]) <= 10, all rows the same length- Each character is
'#'or'.'
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Graphs problems
- Smallest Task OrderMedium
- Smallest Team SplitMedium
- Steps to the ExitMedium
- Through the CheckpointMedium
- Towns Within BudgetMedium
- Break Through WallsHard
- Collect Every KeyHard
- Count the BridgesHard