Close
Topic list
Flip Game II
EASY
15 mins
Other topics
Problem solved
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

# Flip Game II

Contributed by
Prateek_18cb
Easy
0/40
Avg time to solve 15 mins
Success Rate 85 %
Share

## Problem Statement

#### Both the players play the game optimally in alternate turns. Given that Ninja starts the game i.e. takes the first turn, your task is to find out if he wins the game.

##### For example:
``````Let 'STR' = "\$\$**".

There are consecutive "\$\$" in 'STR' and it is Ninja's turn to begin the game. So, Ninja changes the consecutive "\$\$" to "**". This changes 'STR' to "****".

Now, as it is his friend's turn and there are no more consecutive "\$\$", Ninja wins the game.
``````
Detailed explanation ( Input/output format, Notes, Constraints, Images )
##### Sample Input 1:
``````2
\$\$\$\$
****
``````
##### Sample Output 1:
``````true
false
``````
##### Explanation for Sample Output 1:
``````For sample test case 1:

In the first move, Ninja changes the string “\$\$\$\$” to “\$**\$”.
Now there is no consecutive “\$\$” present so Ninja’s friend can not make any move. Hence Ninja wins the game.

For sample test case 2:

There is no consecutive “\$\$” present so Ninja can not make a move. Hence his friend wins the game.
``````
##### Sample Input 2:
``````2
\$\$\$\$\$
**\$\$**\$
``````
##### Sample Output 2:
``````false
true
``````
##### Explanation for Sample Output 2:
``````For sample test case 1:

If the first move, Ninja changes the string “\$\$\$\$\$” to “**\$\$\$”.
Then his friend changes the string “**\$\$\$” to “****\$”.
Now there is no consecutive “\$\$” present so Ninja can not make any move. Hence his friend wins the game.

For sample test case 2:

If the first move, Ninja changes the string “**\$\$**\$” to “******\$”.
Now there is no consecutive “\$\$” present so Ninja’s friend can not make any move. Hence Ninja wins the game.
``````
Auto
Console