FastPrepInitialize a Playable Match-Three Board
Problems/Initialize a Playable Match-Three Board

Initialize a Playable Match-Three Board

Google logoGoogle● EasyNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The author described a very similar interview question, not the exact statement. We kept the goal of a starting board that can be played. The match-three rules, valid sizes, and use of colors are set here. Not every available color must appear. Our version is about 85% the same as the reported question.

Construct a square board with size rows and columns using integer colors from 0 through candyTypes - 1. You may use any subset of the available colors.

A match is a horizontal or vertical run of at least three equal colors. Diagonal runs do not count.

Return any board that satisfies both requirements:

  • The initial board has no match.
  • At least one swap of two horizontally or vertically adjacent cells with different colors creates a match.

The tests check only the starting board and whether a first legal move exists. Do not simulate removals, falling candies, or later moves. The examples show possible outputs; any valid board is accepted.

Function

initializeCandyBoard(size: int, candyTypes: int) → int[][]

Examples

Example 1

size = 3candyTypes = 2return = [[0, 1, 0], [1, 0, 1], [0, 1, 0]]

One possible board uses colors 0 and 1. Swapping cells (0,1) and (1,1) creates a horizontal triple in the top row.

Example 2

size = 4candyTypes = 3return = [[0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 0]]

A palette of three colors is available, but a valid board may use only two. Any valid board is accepted.

Example 3

size = 5candyTypes = 2return = [[0, 1, 0, 1, 0], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0]]

Alternating both rows and columns avoids initial triples on an odd-sized board.

Constraints

  • 3 <= size <= 100.
  • 2 <= candyTypes <= 100.

More Google Onsite Interview questions

  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
  • Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
  • 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

Similar questions at other companies

  • Rotate a Matrix by 90 DegreesIDFC Bank · ONSITE INTERVIEWIDFC Bank interview questions
  • Matrix MultiplicationeBay · ONSITE INTERVIEWeBay interview questions
  • Validate a Two-Color ChessboardAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Traverse Interior Matrix Cells in Row-Major OrderCitadel · ONSITE INTERVIEWCitadel interview questions
  • Detect a Winner on a 3x3 Tic-Tac-Toe BoardHebbia · ONSITE INTERVIEW
  • BitFont Part 1 - Render a CharacterStripe · ONSITE INTERVIEWStripe interview questions
  • Island Perimeter (Round 3, LC 463 :)Microsoft · ONSITE INTERVIEWMicrosoft interview questions
  • Minimum-Step Right-Down Grid PathBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Trace of a Square MatrixAkuna Capital · PHONE SCREEN · ONSITE INTERVIEWAkuna Capital interview questions
  • Unique Rows of a Binary MatrixExpedia · ONSITE INTERVIEWExpedia interview questions

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
  • Google Experienced SWE First Round and Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int[][] initializeCandyBoard(int size, int candyTypes) {
        // Write your code here
    }
}
size3
candyTypes2
reference[[0, 1, 0], [1, 0, 1], [0, 1, 0]]
Checking account…