Problem
Ask
Submissions

Problem: Regions Cut by Slashes

Medium
30 min
Explore how to apply the Union-Find data structure to count adjacent regions in an n by n grid where each cell is divided by slashes, backslashes, or spaces. Understand the problem setup, constraints, and develop an efficient solution to identify connected regions formed by these partitions.

Statement

An n×nn \times n grid is composed of nn, 1×11 \times 1 squares, where each 1×11 \times 1 square consists of a “/”, “\”, or a blank space. These characters divide the square into adjacent regions.

Given the grid represented as a string array, return the number of adjacent regions.

Note:

  1. Backslash characters are escaped, so “\” is represented as “\\”.
  2. A 1×11 \times 1 square in the grid will be referred to as a box.

Constraints:

  • The grid consists of only the “/”, “\”, or " " characters.
  • 1 \leq grid.length \leq 30

The following illustration shows how the grid can be visualized:

canvasAnimation-image
1 / 16
Problem
Ask
Submissions

Problem: Regions Cut by Slashes

Medium
30 min
Explore how to apply the Union-Find data structure to count adjacent regions in an n by n grid where each cell is divided by slashes, backslashes, or spaces. Understand the problem setup, constraints, and develop an efficient solution to identify connected regions formed by these partitions.

Statement

An n×nn \times n grid is composed of nn, 1×11 \times 1 squares, where each 1×11 \times 1 square consists of a “/”, “\”, or a blank space. These characters divide the square into adjacent regions.

Given the grid represented as a string array, return the number of adjacent regions.

Note:

  1. Backslash characters are escaped, so “\” is represented as “\\”.
  2. A 1×11 \times 1 square in the grid will be referred to as a box.

Constraints:

  • The grid consists of only the “/”, “\”, or " " characters.
  • 1 \leq grid.length \leq 30

The following illustration shows how the grid can be visualized:

canvasAnimation-image
1 / 16