Data Structures & AlgorithmsHardICPC regional · Codeforces Div2 D
Problem: Subtraction game: from n stones a player may remove 1, 3 or 4 stones; the player who cannot move loses (no stones left on their turn is a loss). Starting with 10 stones, the first player wins with optimal play. Answer 1 if the first player wins, 0 otherwise.
- A. 1
- B. 2
- C. 0
- D. 3
Correct answer: A. 1
Positions are winning if some move reaches a losing position. The recursion over remaining stones settles the game; a naive parity argument does not apply because the move set is not {1}.
More Coding Interview Problems questions
- Problem: On the 4-cycle C4 (vertices 0-1-2-3-0), a walker starts at 0 and takes exactly 3 steps, each to an adjacent vertex. How many…
- Problem: The array [7, 3, 9, 1, 5] is processed by a selection that finds the position of the maximum, removes it, and repeats. The…
- Problem: How many 4-digit numbers (1000–9999) are palindromes (read the same forwards and backwards in decimal)?
- Problem: The string "abcabcabc" has how many distinct substrings of length 3?
- Problem: What is the number of walks of length 4 that start and end at the same vertex in the complete graph K3 (vertices 0, 1, 2, each…
- Problem: How many integers in [1, 999] have digits that are strictly increasing (each digit larger than the previous)? Run the code…