01 Game

You are given a binary string s consisting only of characters '0' and '1'.

Two players play a turn-based game. In each move, a player must choose two adjacent characters in the string that are different (i.e., 01 or 10) and delete them. The remaining parts of the string are then concatenated.

The player who cannot make a valid move loses the game. Assuming both players play optimally, return true if the first player wins the game, and false otherwise.

Example 1:

Input: s = "01"

Output: true

Explanation:

The first player deletes 01, leaving an empty string. The second player then has no valid moves and loses. The first player wins.

Example 2:

Input: s = "1111"

Output: false

Explanation:

There are no adjacent different characters. The first player cannot make any move initially and loses immediately.

Now Your Turn!

Pick the correct output for the given input

Input: s = "0011"

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= s.length <= 105
  • s consists only of the characters '0' and '1'.

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

0
class Solution {
public:
bool canFirstPlayerWin(string s) {
}
};
Test Case

Input:

S