Connection Status:
Competition Arena > ChamberCount
Rookie SRM 11 · 2022-03-24 · by erinn · Brute Force
Class Name: ChamberCount
Return Type: int
Method Name: count
Arg Types: (vector<string>)
Problem Statement

Problem Statement

You are given a 2D grid of cells in String[] map. Each element of map repreents a single row of the grid, and each character of each element represents a single cell. An 'X' represents a wall, and a '.' represents an open cell.

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 '.'.
Examples
0)
{"...",
 "...",
 "..."}
Returns: 1

The whole map is a single large chamber.

1)
{"XX",
 "XX"}
Returns: 0

With everything being walls, there are no chambers at all.

2)
{".X.",
 "X.X",
 ".X."}
Returns: 5

Remember, only cells that are adjacent horizontally or vertically are part of the same chamber.

3)
{"X...",
 ".XX.",
 "...."}
Returns: 1

Chambers can be weird shapes.

4)
{"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.

Coding Area

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

Submitting as anonymous