Regions Cut By Slashes
An n x n grid is composed of 1 x 1 squares where each 1 x 1 square consists of a '/', '\', or blank space ' '. These characters divide the square into contiguous regions. Given the grid grid represented as a string array, return the number of regions.

30:00

Regions Cut By Slashes
medium
Topics
Companies

An n x n grid is composed of 1 x 1 squares where each 1 x 1 square consists of a '/', '', or blank space ' '. These characters divide the square into contiguous regions. Given the grid grid represented as a string array, return the number of regions.

Example 1:
Input: [" /","/ "]
Output: 2
Constraints:
  • n==grid.length==grid[i].lengthn == \text{grid.length} == \text{grid}[i].\text{length}

  • 1n301 \leq n \leq 30

  • grid[i][j]{’/’,,’ ’}\text{grid}[i][j] \in \{\text{'/'}, \text{'\\\\'}, \text{' '}\}

Input
arr =[" /","/ "]

Expanding 2x2 grid to 6x6 for slash representation

Original Grid
·
/
/
·
Expanded Grid (3x)
Black = slash, Colors = regions
Result
Regions

0

Legend
Slash (wall)
Region 1
Region 2
Variables
No variables to display
DepthFunction Call
Stack empty
0/2