Flip Game II - Problem
You are playing a Flip Game with your friend. You are given a string currentState that contains only '+' and '-'. You and your friend take turns to flip two consecutive "++" into "--".
The game ends when a person can no longer make a move, and therefore the other person will be the winner.
Return true if the starting player can guarantee a win, and false otherwise.
Input & Output
Example 1 — Basic Winning Case
$
Input:
currentState = "++++"
›
Output:
true
💡 Note:
Player 1 can flip the first two ++ to get "--++", then no matter what player 2 does, player 1 can win on the next turn.
Example 2 — No Winning Move
$
Input:
currentState = "+"
›
Output:
false
💡 Note:
Player 1 cannot make any move since there are no consecutive ++ pairs, so player 1 loses immediately.
Example 3 — Complex Case
$
Input:
currentState = "++--++"
›
Output:
true
💡 Note:
Player 1 has two possible moves: flip first ++ or last ++. At least one of these moves leads to a winning strategy.
Constraints
- 1 ≤ currentState.length ≤ 20
- currentState[i] is either '+' or '-'
Visualization
Tap to expand
Understanding the Visualization
1
Input
String with + and - characters
2
Game Rule
Flip consecutive ++ to -- alternately
3
Win Condition
Player who cannot move loses
Key Takeaway
🎯 Key Insight: A game position is winning if there exists at least one move that puts the opponent in a losing position
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code