Problem Statement
The inside of an old warehouse has recently been repurposed as a gallery. The floor of the warehouse is a rectangle that is divided into R rows by C columns of unit squares. Some unit squares are walls ('#'), others contain lamps ('O'), and the rest is empty ('.'). You are given R, C, and the floor plan itself in the String[] floorPlan.
Each lamp illuminates not just its own square but also other empty squares in its row and column - but only until the first wall in each direction.
Compute and return the number of empty squares that will remain in the dark, even if all lamps are turned on.
Definition
- Class:
- GalleryIllumination
- Method:
- countDarkCells
- Parameters:
- int, int, String[]
- Returns:
- int
- Method signature:
- int countDarkCells(int R, int C, String[] floorPlan)
- (be sure your method is public)
Notes
- The character used to represent a lamp is 'O', the capital letter oh (and not '0', the digit zero).
Constraints
- R will be between 1 and 50, inclusive.
- C will be between 1 and 50, inclusive.
- floorPlan will contain R elements.
- Each element of floorPlan will contain C characters.
- Each character in floorPlan will be '#', 'O', or '.'.
Examples
3
4
{"....", "....", "...."}Returns: 12
There are no lights, the whole warehouse is in the dark.4
5
{".....", ".O...", ".....", "....."}Returns: 12
A single light. When we turn it on, the warehouse looks like we show below, with '*' denoting cells that have light. .*... *O*** .*... .*...4
5
{".....", ".OO..", ".....", "....."}Returns: 9
.**.. *OO** .**.. .**..4
5
{".....", ".O#..", ".#.O.", "....."}Returns: 9
In this example we also have two walls that block the light partially. .*.*. *O#*. .#*O* ...*.4
5
{".....", ".O...", "...O.", "....."}Returns: 6
1
1
{"O"}Returns: 0