> For the complete documentation index, see [llms.txt](https://maksimdan.gitbook.io/interview-practice-problems/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://maksimdan.gitbook.io/interview-practice-problems/leetcode_sessions/flip_game_293.md).

# 293 Flip Game

You are playing the following Flip Game with your friend: Given a string that contains only these two characters: + and -, you and your friend take turns to flip twoconsecutive "++" into "--". The game ends when a person can no longer make a move and therefore the other person will be the winner. Write a function to compute all possible states of the string after one valid move. For example, given s = "++++", after one move, it may become one of the following states:

```
    [
      "--++",
      "+--+",
      "++--"
    ]
```

If there is no valid move, return an empty list \[].

```cpp
  #include <iostream>
  #include <string>
  #include <vector>
  using namespace std;

  vector<string> nextPossibleMoves(string s)
  {
      int memory = 0;
      string goBack = s;
      vector<string> moves;
      while (memory < s.size() - 1)
      {
          for (int i = memory; i < s.size(); i++)
          {
              if (i == s.size() - 1) break;
              if (s.at(i) == '+' && s.at(i + 1) == '+')
              {
                  // replace(position, length, string)
                  s = s.replace(i, 2, "--");
                  moves.push_back(s);
                  s = goBack;
                  memory = i + 1;
                  break;
              }
              else memory += 2;
          }
      }
      return moves;

  }

  int main()
  {
      vector<string> moves = nextPossibleMoves("--++--++-----------++++++++++++---++---+++++++---++-+");

      for (auto i : moves) cout << i << endl;
  }
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://maksimdan.gitbook.io/interview-practice-problems/leetcode_sessions/flip_game_293.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
