Reported September 2026
Squarehash table

Map Black Cells to Covering 2x2 Blocks

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

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

Square put this one in front of candidates in September 2026, and the first attempt usually dies on bounds, not logic. The task: for each black cell, list every in-bounds 2x2 block covering it, then sort the records. Grid size goes up to 10^9, so anything that touches the grid itself is dead on arrival. It's a coordinate-math problem wearing a hash-table hint. If you blank on the edge cases during the live OA, StealthCoder runs invisibly as a safety net and gives you the working solution while you keep your cool.

The problem

You are given a grid with rows rows and cols columns, along with the coordinates of every black cell. For each black cell, list every in-bounds 2 x 2 block that contains it.
Rows and columns are zero-indexed. A 2 x 2 block is identified by the coordinate of its top-left cell. The input coordinates are unique but may appear in any order.
Return one flattened record for each black cell. A record has the form [cellRow, cellCol, blockRow1, blockCol1, blockRow2, blockCol2,...]. Sort the records lexicographically by (cellRow, cellCol). Within each record, sort the covering block coordinates lexicographically by (blockRow, blockCol).

Function
mapBlackCellsToBlocks(rows: int, cols: int, blackCells: List<List<Integer>>) → List<List<Integer>>

Examples
Example 1
rows = 4
cols = 5
blackCells = [[2,3],[0,0],[1,2]]
return = [[0,0,0,0],[1,2,0,1,0,2,1,1,1,2],[2,3,1,2,1,3,2,2,2,3]]
The corner cell (0, 0) belongs only to the block at (0, 0). Each interior black cell belongs to four blocks. The returned records are ordered by black-cell coordinate even though the input is not.
Example 2
rows = 2
cols = 4
blackCells = [[1,1],[0,3]]
return = [[0,3,0,2],[1,1,0,0,0,1]]
Because the grid has exactly two rows, every covering block begins in row 0. The right-corner cell (0, 3) belongs only to block (0, 2), while (1, 1) belongs to blocks (0, 0) and (0, 1).
Example 3
rows = 3
cols = 3
blackCells = [[1,1]]
return = [[1,1,0,0,0,1,1,0,1,1]]
The center cell belongs to all four 2 x 2 blocks, whose top-left coordinates are (0, 0), (0, 1), (1, 0), and (1, 1).

Constraints
2 <= rows, cols <= 10^9
0 <= blackCells.length <= 10^5
blackCells[i].length = 2
0 <= blackCells[i][0] < rows
0 <= blackCells[i][1] < cols
All black-cell coordinates are unique.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is that you never build the grid. Each black cell (r, c) can only be covered by blocks with top-left corners at (r-1, c-1), (r-1, c), (r, c-1), (r, c). Keep a corner only if its row is between 0 and rows-2 and its column is between 0 and cols-2. That's the bounds check that sinks most first attempts: people filter against rows-1 or forget the lower bound of 0. Sort the black cells first, then generate the four candidates in lexicographic order (r-1,c-1), (r-1,c), (r,c-1), (r,c), so the inner sort comes free. Flatten each record as cellRow, cellCol, then the block pairs. Complexity is O(n log n) for the sort and O(1) per cell. No hash map is strictly needed since coordinates are unique. Watch out for an empty input, which should return an empty list. If you blank on the ordering or bounds live, StealthCoder is the hedge.

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 Map Black Cells to Covering 2x2 Blocks 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 Square's OA.

Square 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.

Map Black Cells to Covering 2x2 Blocks FAQ

What's the trick in the Square Map Black Cells problem?+

Don't touch the grid. Each cell has at most four candidate blocks, with top-left corners at (r-1,c-1), (r-1,c), (r,c-1) and (r,c). Keep only the ones where the row is in [0, rows-2] and the column is in [0, cols-2]. That's the whole algorithm.

Why can't I just build a 2D grid?+

Rows and cols go up to 10^9, so a grid is impossible in memory or time. You only have up to 10^5 black cells. Work directly from their coordinates and generate the blocks with arithmetic.

How do I get the sorting right?+

Sort the black cells by (row, col) first. For each cell, emit candidate corners in the order (r-1,c-1), (r-1,c), (r,c-1), (r,c). That's already lexicographic, so each record's blocks need no extra sort.

What edge cases should I test before submitting?+

Test corner cells like (0,0) and (rows-1,cols-1), which should give one block each. Test a grid with exactly two rows or two columns, an empty blackCells list, and unsorted input. Example 2 covers the two-row case.

How hard is this one really and how do I prep in 48 hours?+

It's easy to medium. The logic is simple, the risk is off-by-one bounds and output formatting. Write the four-corner bounds check from memory, run the three examples by hand, and practice flattening records. Two hours is enough.

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

OA at Square?
Invisible during screen share
Get it