Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div2 D
Problem: Nim with three piles of sizes 1, 2 and 3. A move removes any positive number of stones from one pile. The player who takes the last stone wins (normal play). How many of the first moves are winning moves (moves after which the player to move next is in a losing position)?
- A. 1
- B. 2
- C. 3
- D. 0
Correct answer: D. 0
A move is winning when it leaves the opponent in a position with no winning reply. In Nim this is decided by the XOR of pile sizes. Counting moves that merely reduce the total stones is a different criterion.
More Coding Interview Problems questions
- Problem: How many subarrays of [1, 2, 3, 0, 3, 2, 1] have a XOR of zero?
- Problem: How many integers from 1 to 50 have exactly two 1-bits in their binary representation?
- Problem: What is the sum of the decimal digits of 9⁹?
- Problem: Arrange the numbers 3, 30, 34, 5, 9 so that their decimal concatenation is the largest possible number. What is that largest…
- Problem: Minimum number of jumps to reach the last index of [2, 3, 1, 1, 4] when from index i you may jump up to a[i] steps forward. What…
- Problem: Find the k-th largest element of [3, 2, 1, 5, 6, 4] for k = 2 (1-indexed among values, with duplicates counted separately).