<p>An <code>n x n</code> grid is composed of <code>1 x 1</code> squares where each <code>1 x 1</code> square consists of a <code>&#39;/&#39;</code>, <code>&#39;\&#39;</code>, or blank space <code>&#39; &#39;</code>. These characters divide the square into contiguous regions.</p>

<p>Given the grid <code>grid</code> represented as a string array, return <em>the number of regions</em>.</p>

<p>Note that backslash characters are escaped, so a <code>&#39;\&#39;</code> is represented as <code>&#39;\\&#39;</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2018/12/15/1.png" style="width: 200px; height: 200px;" />
<pre>
<strong>Input:</strong> grid = [&quot; /&quot;,&quot;/ &quot;]
<strong>Output:</strong> 2
</pre>

<p><strong class="example">Example 2:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2018/12/15/2.png" style="width: 200px; height: 198px;" />
<pre>
<strong>Input:</strong> grid = [&quot; /&quot;,&quot;  &quot;]
<strong>Output:</strong> 1
</pre>

<p><strong class="example">Example 3:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2018/12/15/4.png" style="width: 200px; height: 200px;" />
<pre>
<strong>Input:</strong> grid = [&quot;/\\&quot;,&quot;\\/&quot;]
<strong>Output:</strong> 5
<strong>Explanation: </strong>Recall that because \ characters are escaped, &quot;\\/&quot; refers to \/, and &quot;/\\&quot; refers to /\.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>n == grid.length == grid[i].length</code></li>
	<li><code>1 &lt;= n &lt;= 30</code></li>
	<li><code>grid[i][j]</code> is either <code>&#39;/&#39;</code>, <code>&#39;\&#39;</code>, or <code>&#39; &#39;</code>.</li>
</ul>

class Solution:
    def regionsBySlashes(self, grid: List[str]) -> int:
        r = len(grid) 
        c = len(grid[0]) 
        nr = r*3
       
        nc = c*3
        print(r,nr,c,nc,grid)
        ngrid = [[0]*nc for _ in range(nr)]
        
        # for i in range(nr):
        #     for j in range(nc):
        #         ngrid[i][j] = 0
        print(ngrid)
        for i in range(r):
            for j in range(c):
                if grid[i][j] == "/":
                    ni = 3*i
                    nj = 3*j
                    ngrid[ni][nj+2] = 1
                    ngrid[ni+1][nj+1] = 1
                    ngrid[ni+2][nj] = 1
                elif grid[i][j] == "\\":
                    ni = 3*i
                    nj = 3*j
                    ngrid[ni+2][nj+2] = 1
                    ngrid[ni+1][nj+1] = 1
                    ngrid[ni][nj] = 1
        def dfs(i,j):
            if i < 0 or j < 0 or i >= nr or j >= nc or ngrid[i][j] != 0 or (i,j) in visited:
                return
            delts = [[0,1],[1,0],[0,-1],[-1,0]]
            visited.add((i, j))
            for dx,dy in delts:
                dfs(i+dx, j+dy) 

        visited = set()
        region = 0
        for i in range(nr):
            for j in range(nc):
                if (i,j) not in visited and ngrid[i][j] == 0:
                    dfs(i,j)
                    region += 1
        return region

        # numRegion = 0
        # visited = set()
        # r2 = len(grid) * 3
        # c2 = len(grid[0]) * 3
        
        # # Initialize grid2 with 0s
        # grid2 = [[0] * c2 for _ in range(r2)]
        
        # # Fill grid2 based on slashes in the original grid
        # for i in range(len(grid)):
        #     for j in range(len(grid[0])):
        #         if grid[i][j] == "/":
        #             i2 = 3 * i
        #             j2 = 3 * j
        #             grid2[i2][j2 + 2] = 1
        #             grid2[i2 + 1][j2 + 1] = 1
        #             grid2[i2 + 2][j2] = 1
        #         elif grid[i][j] == "\\":
        #             i2 = 3 * i
        #             j2 = 3 * j
        #             grid2[i2][j2] = 1
        #             grid2[i2 + 1][j2 + 1] = 1
        #             grid2[i2 + 2][j2 + 2] = 1

        # def dfs(r, c):
        #     if (r, c) in visited or r < 0 or r >= r2 or c < 0 or c >= c2 or grid2[r][c] == 1:
        #         return
        #     visited.add((r, c))
        #     delta = [[-1, 0], [1, 0], [0, -1], [0, 1]]
        #     for dr, dc in delta:
        #         dfs(r + dr, c + dc)

        # # Count regions
        # for i in range(r2):
        #     for j in range(c2):
        #         if grid2[i][j] == 0 and (i, j) not in visited:
        #             dfs(i, j)
        #             numRegion += 1

        # return numRegion

22453