Can the Current Player Win Babylon?
Updated
Problem statement
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[]) → booleanExamples
Example 1
heights = [1,1]topColors = ["R","B"]return = trueThe current player merges the equal-height piles and leaves no move.
Example 2
heights = [1,2]topColors = ["R","B"]return = falseThe two piles share neither height nor color, so no move is legal.
Example 3
heights = [1,1,1]topColors = ["R","G","B"]return = trueMerge 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