FastPrepCan the Current Player Win Babylon?
Problems/Can the Current Player Win Babylon?

Can the Current Player Win Babylon?

Google logoGoogle● HardNEW GRADPHONE SCREEN

Updated Oct 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The firsthand Google new-grad report gives the complete Babylon rules: twelve initial unit piles, four colors with three tiles each, legal merges by equal height or equal top color, merged top color chosen by orientation, and normal play. A commenter proposes memoized DFS over pile states and the author confirms it. FastPrep accepts any reachable small state so the same game-search logic is judgeable.

A Babylon game state contains several tile piles. heights[i] is the height of pile i, and topColors[i] is its top color. Two players alternate moves.

On a move, choose two different piles and place one whole pile on top of the other. The move is legal when the two piles have the same height or the same top color. The merged pile's height is the sum of both heights, and its top color is the top color of the pile placed on top.

A player who has no legal move loses. Assuming optimal play from both players, return whether the current player can force a win.

Function

canCurrentPlayerWin(heights: int[], topColors: String[]) → boolean

Examples

Example 1

heights = [1,1]topColors = ["R","B"]return = true

The current player merges the equal-height piles and leaves no move.

Example 2

heights = [1,2]topColors = ["R","B"]return = false

The two piles share neither height nor color, so no move is legal.

Example 3

heights = [1,1,1]topColors = ["R","G","B"]return = true

Merge any two equal-height piles. The remaining piles then have different heights and colors, so the opponent has no move.

Constraints

  • 1 <= heights.length = topColors.length <= 12.
  • 1 <= heights[i] <= 12.
  • Each color is a non-empty uppercase string.
  • The sum of all heights is at most 12.

More Google Phone Screen questions

  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Periodic-Color Binary Forest RootsPHONE SCREEN · Seen Nov 2026
  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
  • Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
  • Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
  • Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Word Break IIAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Word Break IIWex · PHONE SCREEN
  • Maximum Currency Conversion Along a Simple PathRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
  • Word Break IIInMobi · PHONE SCREENInMobi interview questions
  • Find GPU Capacity and Drain a NodeTogether AI · PHONE SCREEN
  • Word Break IIBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Word Break II: All SentencesMicrosoft · PHONE SCREEN · ONSITE INTERVIEWMicrosoft interview questions
  • Maximum Words in Disjoint Grid PathsIndeed · PHONE SCREENIndeed interview questions
  • Count Complete Tic-Tac-Toe GamesDecagon · PHONE SCREEN · ONSITE INTERVIEWDecagon interview questions
  • Red and Black Tile MovesWhatNot · PHONE SCREENWhatNot interview questions

Interview reports that mention this question

  • Google New Grad R1, Babylon Game: 1 Experience

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
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public boolean canCurrentPlayerWin(int[] heights, String[] topColors) {
        // Write your code here.
    }
}
Checking account…