 All Problems
Regions Cut By Slashes
medium
union-find
graph
matrix
google
amazon

An n x n grid is composed of 1 x 1 squares where each square is either empty ' ', a slash '/', or a backslash '\\'. These slashes divide the square into regions.

Given the grid, return the number of regions.

Example 1:

Input: grid = [" /","/ "]
Output: 2

Example 2:

Input: grid = [" /","  "]
Output: 1

Constraints: 1 <= grid.length <= 30

Run to check your code against the sample cases, or submit to run every case