This question evaluates understanding of combinatorial game theory, impartial game analysis, state-space encoding, and efficient state-space search techniques.
You are given a two-player turn-based game. There are n stacks of tiles. Each stack has:
Y
,
W
,
G
,
B
)
n
stacks, each of
height = 1
.
i
-th stack’s top color is
colors[i]
.
On your turn, you must pick two different stacks A and B and merge the entire stack A onto the top of stack B, but only if at least one condition holds:
height(A) == height(B)
, or
topColor(A) == topColor(B)
After merging:
height(B) = height(A) + height(B)
topColor(B) = topColor(A)
(because
A
is placed on top)
A
is removed (total number of stacks decreases by 1)
Given the initial colors array, determine whether the first player has a winning strategy assuming optimal play from both players.
Return true if the first player can force a win; otherwise return false.
1 <= n <= 12
colors[i]
is in
{ 'Y','W','G','B' }
colors = ["Y","Y"]
true
.