ChamberCount
Rookie SRM 11 · 2022-03-24 · by erinn
Problem Statement
You are given a 2D grid of cells in
We call a set of connected open cells a chamber. Any two '.' cells which are adjacent horizontally or vertically are part of the same chamber.
Return the number of distinct chambers represented in the map.
Constraints
- map will contain between 1 and 50 elements.
- Each element of map will contain between 1 and 50 characters.
- Each element of map will be the same length.
- Each character of each element of map will be 'X' or '.'.
{"...",
"...",
"..."}
Returns: 1
The whole map is a single large chamber.
{"XX",
"XX"}
Returns: 0
With everything being walls, there are no chambers at all.
{".X.",
"X.X",
".X."}
Returns: 5
Remember, only cells that are adjacent horizontally or vertically are part of the same chamber.
{"X...",
".XX.",
"...."}
Returns: 1
Chambers can be weird shapes.
{"X...",
".XX.",
"..X."}
Returns: 2
Submissions are judged against all 20 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class ChamberCount with a public method int count(vector<string> map) · 20 test cases · 2 s / 256 MB per case