Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2 B
A four-wheel combination lock shows four digits 0–9 on wheels that wrap around (9 goes to 0 and 0 goes to 9). One move turns one wheel by one step up or down. The lock starts at 0000 and must reach the code 6463. These codes are dead ends and may never be shown at any moment: 0219, 0595, 0745, 1098, 1813, 2217, 2236, 2372, 2545, 2675, 4052, 4287, 4610, 4895, 4992, 5041, 5677, 5686, 5866, 6386, 6865, 7742, 7907, 8033, 8466, 8597, 8990. What is the minimum number of moves?
- A. 15
- B. 19
- C. 4
- D. 17
Correct answer: A. 15
BFS over codes that skips the dead ends finds 15 moves; here no dead end lies on a shortest route, so it equals the sum of circular wheel distances (4 + 4 + 4 + 3). 19 turns each wheel without wrapping, 4 is only the largest single-wheel distance, and 17 assumes a dead end forces a two-move detour.
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 tree has vertices with weights in brackets: D[15], C[15], R[7], L[9], S[1], Z[3], B[13], H[13], F[6]. The edges are D–C, D–R, R–L, D–S…
- A tree on the vertices C, F, H, L, P, V, W has the arcs V→P, F→P, P→C, F→H, V→L, W→H (each undirected edge is directed as shown). You may…
- Each cell of a grid with 3 rows and 4 columns has an arrow: R = right, L = left, U = up, D = down. RRLL URUU RRUD From a cell you may move…
- A counter starts at 1. Each step, you may add 1, add 2, or double the counter. Each step must stay at or below 18. Two sequences of steps…
- A pile holds p stones. In one move a player removes exactly s stones, where s is one of {2, 3, 4} and s ≤ the pile size. The player who…
- A connected undirected graph has the vertices B, F, K, N, U, W and weighted edges (weights in brackets): F–U (13), F–N (4), N–U (17), B–W…