Given a row of silver coins among which a special gold coin is present. Two players play the game, and with each move, a player has to remove a coin from either the left or the right end of the row and the player who removes the special coin wins the game. The task is to find the winner of the game.
Input: str = “GSSS”
The first player directly removes the special gold coin.
Input: str = “SGS”
Irrespective of which coin the first player removes, the special
gold coin becomes exposed and is removed by the second player.
Approach: It can be observed by taking a few examples that if the count of the silver coins is odd then the first player wins the game otherwise the player two wins the game. In special case when Gold coin is in corner, First player will be the winner regardless the count of silver coins.
Below is the implementation of the above approach:
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Optimal Strategy for a Game | DP-31
- Optimal Strategy for a Game | Set 3
- Optimal strategy for a Game with modifications
- Puzzle 14 | (Strategy for a 2 Player Coin Game)
- Optimal Strategy for the Divisor game using Dynamic Programming
- Game Theory (Normal-form game) | Set 3 (Game with Mixed Strategy)
- Game Theory (Normal-form Game) | Set 5 (Dominance Property-Mixed Strategy)
- Game Theory (Normal-form Game) | Set 4 (Dominance Property-Pure Strategy)
- Find the player who will win the Coin game
- Predict the winner in Coin Game
- Coin game of two corners (Greedy Approach)
- Puzzle | (Round table coin game)
- Minimax Algorithm in Game Theory | Set 3 (Tic-Tac-Toe AI - Finding optimal move)
- Game Theory (Normal-form Game) | Set 7 (Graphical Method [M X 2] Game)
- Game Theory (Normal-form Game) | Set 6 (Graphical Method [2 X N] Game)