Flip Game - Problem

You are playing a Flip Game with your friend. You are given a string currentState that contains only '+' and '-' characters.

You and your friend take turns to flip two consecutive "+" characters into "--". The game ends when a person can no longer make a move, and therefore the other person will be the winner.

Return all possible states of the string currentState after one valid move. You may return the answer in any order. If there is no valid move, return an empty list.

Input & Output

Example 1 — Single ++ Pair
$ Input: currentState = "+--++"
Output: ["+----"]
💡 Note: Only one ++ pair exists at positions 3-4, flipping it gives "+----"
Example 2 — Multiple ++ Pairs
$ Input: currentState = "++--++"
Output: ["----++", "++----"]
💡 Note: Two ++ pairs: positions 0-1 and 4-5. Flipping first gives "----++", flipping second gives "++----"
Example 3 — No Valid Moves
$ Input: currentState = "+-+-"
Output: []
💡 Note: No consecutive ++ pairs exist, so no valid moves possible

Constraints

  • 1 ≤ currentState.length ≤ 500
  • currentState[i] is either '+' or '-'

Visualization

Tap to expand
Flip Game: Transform "++--++" → All Possible Next StatesInput:++--++Flip thisFlip thisOutput:Move 1: "----++"Move 2: "++----"Result Array["----++", "++----"]Two ++ patterns found → Two possible moves
Understanding the Visualization
1
Input
String with + and - characters
2
Process
Find all ++ patterns and flip each to --
3
Output
Array of all possible states after one move
Key Takeaway
🎯 Key Insight: Scan for consecutive '+' pairs and generate new states by flipping each to '--'
Asked in
Google 15 Facebook 12
28.0K Views
Medium Frequency
~15 min Avg. Time
892 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