I was asked this question a while ago at my Google interview and so far I had no luck finding a good answer to it: This is a 2-player game where you are given a string of zeros and ones. At each turn a player can choose a 1 (or as many 1s next to each other) and change it/them to 0/0s. The player who changes the last 1 (or group of 1s) to 0/0s is the winner of the game.
For example starting with 0101110. The first player has 7 possible moves:
- 0101110 -> 0001110 (Second player can win)
- 0101110 -> 0100110 (Second player can win)
- 0101110 -> 0101010 (Second player can win)
- 0101110 -> 0101100 (Second player can win)
- 0101110 -> 0100010 (First player can win)
- 0101110 -> 0101000 (First player can win)
- 0101110 -> 0100000 (Second player can win)
The goal is to figure out if there is a winning strategy if you start first. We assume here that both players are good players (meaning that they wont make mistakes!)
Update: This game is slightly different than Nim (https://en.wikipedia.org/wiki/Nim), for Nim the number of piles (or heaps) remain the same at every turn whereas here at every turn you may change the number of piles. For instance if we do 0101110 -> 0101010 initially we have two piles of size 1 and 3 but after the move we will have 3 piles of size 1.
101? The player who moves first loses in this case, since they are forced to change one of the1s, so the second player can win on their turn. - arshajii