Given an n x n grid containing forward and back slash characters, return the number of regions formed after drawing the slashes. A common DSU approach is to split each cell into four triangles and detect cycles when triangles are already connected.
grid = array of slash strings
number of regions formed by the slashes
Example 1:
Input:
grid = [" /","/ "]
Output:
2
Explanation:
The two slashes divide the square into two regions.
Example 2:
Input:
grid = [" /"," "]
Output:
1
Explanation:
Only one slash exists, so there is a single connected region.
Example 3:
Input:
grid = ["\\/","/\\"]
Output:
4
Explanation:
The crossing slash layout creates multiple enclosed regions.