/294. Flip Game II

294. Flip Game II

Medium
Probability52.3% acceptance

Given a string consisting of only + and -, two players take turns flipping two consecutive + characters to --. The player who cannot make a move loses. Determine if the starting player can guarantee a win assuming both players play optimally.

Example 1

Input: ++--+++

Output: True

Explanation: The starting player can flip the first two + to --, leaving --+--++. The second player cannot win.

Example 2

Input: ++++-

Output: True

Explanation: The starting player can flip the first two + to --, leaving --++-. The second player cannot win.

Example 3

Input: --++--

Output: False

Explanation: No move can be made by the starting player.

Constraints

  • 1 <= len(initial_state) <= 100
  • initial_state consists only of + and - characters
Python (current runtime)

Case 1

Input: '++-+++'

Expected: True

Case 2

Input: '++--++'

Expected: False

Case 3

Input: '++++++'

Expected: True

Case 4

Input: '--+--+'

Expected: False