FastPrepCount Matching Regions in Two Binary Grids
Problems/Count Matching Regions in Two Binary Grids

Count Matching Regions in Two Binary Grids

OpenAI logoOpenAI● MediumOA
QuestionFunctionExamples

Problem statement

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.

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.

Function

countMatchingRegions(grid1: String[], grid2: String[]) → int

Examples

Example 1

grid1 = ["001","011","100"]grid2 = ["001","011","101"]return = 1

The 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

  • Determine the Winner of Three-Card HandsPHONE SCREEN · Seen Nov 2026
  • Sparse Plant Infection SimulationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Light Source Hits: Sample, Compare, and FitPHONE SCREEN · Seen Nov 2026
All OpenAI interview questionsSee OpenAI hiring insights
Saved
class Solution {
    public int countMatchingRegions(String[] grid1, String[] grid2) {
      // write your code here
    }

}
Checking account…