1133. Crossword Slot Count
A newspaper puzzle editor wants to know how many answers a crossword grid can hold. The array rows describes the grid: every string is one row, all rows have the same length, '.' is an open cell and '#' is a blocked cell.
A slot is a maximal horizontal run or a maximal vertical run of consecutive open cells, and it counts only when it has at least 2 cells. Return the total number of slots, horizontal and vertical together. One open cell can belong to a horizontal slot and a vertical slot, and both are counted. Scan every row once and every column once for O(m*n) time and O(1) extra space.
Example 1
- Input:
- rows = ["..#","...","#.."]
- Output:
- 6
- Explanation:
There are 3 horizontal and 3 vertical runs of at least 2 open cells, so the answer is 6.
Example 2
- Input:
- rows = ["#.#",".#.","#.#"]
- Output:
- 0
- Explanation:
There are 0 horizontal and 0 vertical runs of at least 2 open cells, so the answer is 0.
Example 3
- Input:
- rows = [".....","#...#"]
- Output:
- 5
- Explanation:
There are 2 horizontal and 3 vertical runs of at least 2 open cells, so the answer is 5.
Constraints
1 ≤ rows.length ≤ 50
All rows have the same length, between 1 and 50
Each character is '.' or '#'
How this problem is judged
- Answers
- Your answer must match exactly. Numbers compare by value, so 2 and 2.0 are equal.
Expected complexity
- Time
- O(m*n)
- Space
- O(1)