Count Matching Regions in Two Binary Grids
Learn this problemProblem statement
You are given two rectangular binary grids, grid1 and grid2. Each grid is represented by an array of strings, where '1' is a filled cell and '0' is an empty cell.
A region is a maximal group of filled cells connected horizontally or vertically. Two regions match when they contain exactly the same cell coordinates, one in each grid.
Return the number of matching regions.
Source note: The report shared the binary-grid input format, the worked sample below, and identified connected-region search as the first coding task. This version closely follows that core task; the original function signature and numeric limits were not shown.
Function
countMatchingRegions(grid1: String[], grid2: String[]) → intExamples
Example 1
grid1 = ["001","011","100"]grid2 = ["001","011","101"]return = 1The first grid has regions {(0,2), (1,1), (1,2)} and {(2,0)}. The second has regions {(0,2), (1,1), (1,2), (2,2)} and {(2,0)}. Only the single-cell region matches exactly.
More OpenAI problems
- Memory AllocatorPHONE SCREEN · Seen Jul 2026
- Message Event AggregationONSITE INTERVIEW · Seen Jul 2026
- Plant Infection Simulation, Part 4: Death CountdownPHONE SCREEN · Seen Jun 2026
- Streaming Entropy, Part 1: Batch EntropyONSITE INTERVIEW · Seen Jun 2026
- Streaming Entropy, Part 2: Numerically Stable EntropyONSITE INTERVIEW · Seen Jun 2026
- Streaming Entropy, Part 3: Block-wise EntropyONSITE INTERVIEW · Seen Jun 2026
- Streaming Entropy, Part 4: Stable Streaming EntropyONSITE INTERVIEW · Seen Jun 2026
- Resumable List IteratorPHONE SCREEN · Seen Jun 2026