Data Structures & AlgorithmsModerateGATE CS · ICPC regional
A pile holds p stones. In one move a player removes exactly s stones, where s is one of {2, 3} and s ≤ the pile size. The player who cannot move (pile 0) loses. For how many starting piles p with 1 ≤ p ≤ 19 is the position a LOSS for the player to move?
- A. 12
- B. 8
- C. 7
- D. 6
Correct answer: C. 7
Mark positions from 0 upward: p is losing exactly when no allowed s leads to a losing position. There are 7 losing piles in 1 to 19. Counting the winning ones instead gives 12, and including pile 0 gives 8.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- A directed graph has the vertices B, H, L, Q, R, T, U, Z and the arcs B→L, B→H, B→R, B→Q, L→B, L→Z, L→H, Z→B, Z→L, Z→T, H→L, H→U, R→B…
- The directed acyclic graph has the vertices A, I, L, P, Q, W and the arcs W→P, I→A, W→I, L→I, Q→A, L→W, L→Q, L→A. How many distinct…
- An undirected graph has the vertices B, G, S, T, Y and the edges S–B, G–S, S–Y, S–T, B–T, G–Y, B–Y. What is the minimum number of edges…
- A directed acyclic graph has the vertices A, B, K, S, X, Y and the edges B→K, B→S, B→Y, B→X, S→K, Y→S, Y→X. A topological order lists…
- Keys 50, 30, 70, 20, 40, 60, 80, 35, 45, 65 are inserted in order into an empty BST. Then 30 is deleted, then 50 is deleted; a node with…
- The array [3, 9, 2, 1, 4, 5, 8] is converted to a max-heap by Floyd's bottom-up method, sifting down from the last parent to the root…