FastPrepValidate Rectangular Game Pieces
Problems/Validate Rectangular Game Pieces

Validate Rectangular Game Pieces

Google logoGoogle● MediumINTERNONSITE INTERVIEW

Updated Oct 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report describes a two-dimensional game-board validation task but does not identify the game or its validity rules. Piece IDs and the filled-rectangle rule are practice assumptions. Approximate source match: 20%.

You are given a non-empty rectangular grid called board. Each cell contains an integer:

  • 0 means 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[][]) → boolean

Examples

Example 1

board = [[2,2,0,7],[2,2,0,7],[0,0,0,7]]return = true
board
0123022071220720007

Piece 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 = false
board
01044140

The smallest rectangle containing piece 4 has four cells, but one is empty.

Example 3

board = [[5,0,5]]return = false
board
0120505

The 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 <= 200
  • 1 <= 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

Interview reports that mention this question

  • Google Intern Coding and OOP: 19 Experiences (Part 5 of 8)

Google interview experiences

  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
  • Google Experienced SWE First Round and Onsite: 1 Experience
  • Google AI Coding Interview and AI OA: 2 Experiences
  • Google SWE Intern Interview Results Timeline: 13 Experiences
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public boolean isValidPieceBoard(int[][] board) {
        // write your code here
    }
}
Checking account…