Reported July 2026
OpenAIdepth first search

Count Matching Regions in Two Binary Grids

Reported by candidates from OpenAI's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live OpenAI OA. Under 2s to a working solution.
Founder's read

The mistake that sinks a first attempt on this one is checking whether a region in grid2 is a subset of grid1, then calling it done. This OpenAI question, reported in July 2026, asks you to count connected regions that are identical by coordinates in both grids. It's a flood fill problem with one twist. If you've seen island counting, you're 80 percent there. If you blank on the twist, StealthCoder runs invisibly during the live OA and can hand you a working solution. Read the matching rule twice before you write any code.

The problem

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.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is that a region matches only if its exact cell set is the same in both grids. So run DFS or BFS over grid1, collect each region's cells, and for every cell check that grid2 is also '1'. Then confirm the grid2 region reached from that start has the same size. The pitfall is checking only one direction. In Example 1, the region {(0,2),(1,1),(1,2)} sits inside grid2's larger region with (2,2), so a subset check would wrongly count it. Fix: flood-fill both grids from the same start, compare sizes, and make sure every cell is filled in both. Or label regions in each grid and compare the sets of cells. Complexity is O(rows x cols). Use an iterative stack if the grids can be big. StealthCoder is your hedge if the size comparison slips your mind under pressure.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Count Matching Regions in Two Binary Grids cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass OpenAI's OA.

OpenAI reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Count Matching Regions in Two Binary Grids FAQ

What's the trick in Count Matching Regions in Two Binary Grids?+

Matching means identical cell coordinates, not overlap or containment. Flood-fill a region in grid1, then check that the same cells form a complete region in grid2 with no extra connected cells. Compare region sizes from both grids to catch the superset case from the example.

How hard is this OpenAI OA question really?+

Medium. The traversal is standard island counting. The difficulty is the matching condition, which people get wrong by checking only one grid. Once you flood-fill both grids and compare cell sets or sizes, the code is short and clean.

Should I use DFS or BFS here?+

Either works. BFS or an explicit stack avoids recursion depth problems on large grids. Pick whichever you can write without bugs. The complexity is the same, O(rows x cols), and the visited array matters more than the traversal choice.

What edge cases should I test?+

Test grids with no filled cells, which should return 0. Test a region in grid1 that grows larger in grid2, as in the example. Test a single cell region, and regions that touch only diagonally, which are not connected under this rule.

How do I prepare for this in 48 hours?+

Write island counting from scratch twice, then add the second grid comparison. Practice returning region cell sets or sizes from a flood fill. That covers the whole pattern. Don't memorize this exact problem, since the matching rule is the only new part.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with OpenAI.

OA at OpenAI?
Invisible during screen share
Get it