Reported September 2026
Databrickshash table

Rectangular K-in-a-Row

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

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

The Databricks OA reported in September 2026 hands you a giant board, up to 10^9 by 10^9, and asks who completes k in a row after each move. The trick is the data structure. You can't allocate a grid, so you store only the placed marks in a hash map keyed by cell, then check the four line directions around each new move. If you blank on the setup during the live assessment, StealthCoder runs invisibly as a safety net and reads the problem for you. But the idea is simple enough to own before you sit down.

The problem

An empty game board has rows rows and columns columns. Two players, numbered 1 and 2, place marks through the ordered array moves. Each move is [row, column, player].
After placing a mark, that player wins if the new mark belongs to a contiguous run of at least k marks by the same player in any one of four directions:
horizontal,
vertical,
the top-left to bottom-right diagonal, or
the top-right to bottom-left diagonal.
Return one result for every move. The result is the winning player number if that move completes a winning run; otherwise it is 0.
Rows and columns use zero-based indexing. Every move is inside the board and targets an empty cell. The sequence ends immediately after the first winning move, so no move is made after a winner exists.

Function
playKInARow(rows: int, columns: int, k: int, moves: int[][]) → int[]

Examples
Example 1
rows = 3
columns = 3
k = 3
moves = [[0,0,1],[0,1,2],[1,1,1],[0,2,2],[2,2,1]]
return = [0,0,0,0,1]
Player 1 completes the main diagonal at [2,2]. No earlier move forms three contiguous marks.
Example 2
rows = 3
columns = 5
k = 4
moves = [[0,0,1],[1,0,2],[0,1,1],[1,1,2],[2,4,1],[1,2,2],[2,3,1],[1,3,2]]
return = [0,0,0,0,0,0,0,2]
On the final move, player 2 owns four consecutive cells from column 0 through column 3 in row 1.
Example 3
rows = 2
columns = 2
k = 1
moves = [[1,0,2]]
return = [2]
When k = 1, the first valid mark is already a winning run of length one.

Constraints
1 <= rows, columns <= 10^9
1 <= k <= max(rows, columns)
1 <= moves.length <= 200000
Every move has exactly three integers [row, column, player].
0 <= row < rows and 0 <= column < columns.
player is either 1 or 2.
No cell appears in more than one move.
The sequence stops immediately after the first winning move.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Use a hash map from (row, column) to player. Moves are capped at 200000, so the board size never matters. After each move, for each of the four directions (horizontal, vertical, both diagonals), count contiguous same-player cells going one way, then the opposite way, add 1 for the new mark, and compare to k. Each direction walks at most k cells per side, and a run can't exceed the number of moves, so cap the walk sensibly. The common pitfall is building a 2D array, which blows memory instantly. Another is encoding the key as row * columns + column in a language with 32-bit ints. Use a 64-bit key or a string or tuple key. Also remember k = 1 wins on the first move, and the sequence ends at the first win. If the walk logic slips under pressure, StealthCoder is the hedge on the live OA.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

If this hits your live OA

You can drill Rectangular K-in-a-Row 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. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.

Get StealthCoder

Related leaked OAs

⏵ The honest play

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

Databricks reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Rectangular K-in-a-Row FAQ

What's the trick in Rectangular K-in-a-Row?+

Don't build the board. With dimensions up to 10^9, store only placed marks in a hash map keyed by cell. After each move, count contiguous same-player marks in both directions along four lines and check if the total reaches k.

How do I encode the cell key safely?+

Use row * columns + column in a 64-bit integer, which fits since 10^9 times 10^9 is 10^18. In Python any int works. In Java use long, not int. A tuple or string key also works but is slower at 200000 moves.

What's the time complexity?+

Each move checks four directions and walks up to k cells per side, with O(1) hash lookups. That's O(n * k) worst case for n moves. Walks stop at the first empty or opposing cell, so real runs are much shorter. It's fine for 200000 moves.

What edge cases break solutions?+

k = 1 means the first move wins. Counting the new mark twice is a classic off-by-one. Mixing up the two diagonals is another. Also return one result per move, with zeros until the winning move, and the input stops after the first win.

How do I prepare for this in 48 hours?+

Write the direction-counting routine from scratch using direction vectors like (0,1), (1,0), (1,1), (1,-1). Test it on the three examples. Then try a sparse-board variant using a dict so you're comfortable with hashed coordinates and not grids.

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

OA at Databricks?
Invisible during screen share
Get it