Count Regions Carved by Slashes in a Grid of Map Tiles

Last updated: November 29, 2026

Quick Overview

An n by n grid of map tiles has each cell containing '/', '\\', or a blank. The slashes act as walls drawn corner to corner. Return how many separate regions the grid is divided into.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


An n by n grid of map tiles has each cell containing '/', '\\', or a blank. The slashes act as walls drawn corner to corner. Return how many separate regions the grid is divided into.

A Google onsite question about modeling geometry as a graph, relevant to map rendering and polygon tiling. The interviewer is checking whether you subdivide cells (into four triangles, or upscale to a 3x3 pixel grid), wire the pieces with union-find, and keep the indexing bug-free.

What the Interviewer Expects
  • Splits each cell into four triangles: top, right, bottom, left
  • Joins triangles inside a cell according to the character
  • Joins triangles across neighboring cells
  • Counts the resulting components
  • Traces at least one small grid by hand
Key Topics to Cover
Union-Find
Grid
Geometry Modeling
Connected Components
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Solve it by upscaling each cell to 3x3 pixels and flood filling. What are the trade-offs?
  • What if cells may contain both slashes, forming an X?
  • Report the area of the largest region.
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Input: list of n strings of length n, characters /, \\, or space.
  • Output: number of regions.
  • Slashes run between opposite corners of a cell....
High-Level Design

Divide every cell into four triangles by its two diagonals: 0 top, 1 right, 2 bottom, 3 left. A / separates top-left from bottom-right, so top joins left and right joins bottom. A backslash joins to...


Submit Your Answer
Markdown supported