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
Flip Game II: Can Player 1 Guarantee a Win?Game Rule: Flip consecutive "++" to "--" on each turnInitial State+ + + +Player 1 Turn: Choose which ++ to flip- - + ++ - - ++ + - -Option 1Option 2Option 3Analyze each option recursively...If ANY option leads to opponent losing:Player 1 can guarantee a win!Use memoization to cache results for efficiency
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
Asked in
Google 15 Facebook 12 Microsoft 8 Amazon 6
32.0K Views
Medium Frequency
~25 min Avg. Time
890 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen