Validate Rectangular Game Pieces
Updated
Problem statement
You are given a non-empty rectangular grid called board. Each cell contains an integer:
0means the cell is empty.- A positive number is a piece ID. All cells with the same ID belong to the same piece.
In this practice exercise, each piece must form one filled rectangle whose sides follow the board's rows and columns. Every cell inside that rectangle must have the same piece ID. There cannot be gaps or cells from another piece inside it.
A rectangle can be one cell wide, one cell tall, or just one cell. Different pieces may touch at their sides or corners. Piece IDs may skip numbers.
Return true if every piece follows these rules. Otherwise, return false. A board with only empty cells is valid.
Only check these placement rules; there are no rules about turns, moves, or winning. Do not change board.
Function
isValidPieceBoard(board: int[][]) → booleanExamples
Example 1
board = [[2,2,0,7],[2,2,0,7],[0,0,0,7]]return = truePiece 2 is a filled 2 by 2 rectangle. Piece 7 is a filled 3 by 1 rectangle.
Example 2
board = [[4,4],[4,0]]return = falseThe smallest rectangle containing piece 4 has four cells, but one is empty.
Example 3
board = [[5,0,5]]return = falseThe two cells with ID 5 belong to the same piece. The empty cell between them prevents that piece from forming a filled rectangle.
Constraints
1 <= board.length <= 2001 <= board[0].length <= 200- Every row has the same length.
0 <= board[row][column] <= 10^9
More Google Onsite Interview questions
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
- Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Filesystem Entity Total SizeONSITE INTERVIEW · Seen Nov 2026
- Longest Subarray Within an Absolute-Difference LimitONSITE INTERVIEW · Seen Nov 2026
- Reach a Destination Through Scheduled FlightsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Sudoku Board ValidationConfluent · PHONE SCREEN · ONSITE INTERVIEWConfluent interview questions
- Set Matrix ZeroesMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Query Whether an Island Size ExistsMeta · ONSITE INTERVIEWMeta interview questions
- Validate a Sudoku BoardZipRecruiter · ONSITE INTERVIEWZipRecruiter interview questions
- Check a Partly Filled Sudoku GridExpedia · ONSITE INTERVIEWExpedia interview questions
- Cache Shared Image Pipeline PrefixesAnthropic · ONSITE INTERVIEWAnthropic interview questions
- Sparse Matrix MultiplicationByteDance · PHONE SCREENByteDance interview questions
- First Completed Mingo LineEpic · OAEpic interview questions
- Valid SudokuVerkada · PHONE SCREENVerkada interview questions
- Count 2x2 Submatrices by Black CellsTikTok · OATikTok interview questions