Data Structures & AlgorithmsHardCodeforces Div 2 C · GATE CS
Starting from the integer 13, one operation either adds 1, subtracts 1, or doubles the current value. Values may be any non-negative integers. What is the minimum number of operations needed to reach exactly 184?
- A. 171
- B. 7
- C. 13
- D. 6
Correct answer: D. 6
A BFS over the integers gives 6 operations. Peeling back from 184 with halving-when-even gives 13; using only +1 and doubling (no subtraction) needs 13.
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
- Floyd–Warshall runs on vertices 1 to 5 with these arcs u→v (weight): 1→2 (12), 1→4 (1), 1→5 (8), 2→1 (10), 2→3 (2), 2→4 (7), 3→1 (1), 3→5…
- An undirected connected graph on the vertices D, L, R, T, V has the edges D–V, L–R, D–T, V–R, L–T, L–V, V–T, L–D. How many spanning trees…
- Each cell of a grid with 4 rows and 5 columns has an arrow: R = right, L = left, U = up, D = down. RUUUD RLDUL UDLDR RDDRU From a cell you…
- Starting from the integer 9, one operation either adds 1, subtracts 1, or doubles the current value. Values may be any non-negative…
- Two unmarked jugs hold 7 litres and 8 litres. Allowed operations: fill a jug completely, empty a jug completely, or pour one jug into the…
- Cities A, B, N, T, U are joined by roads with these travel costs: A–N 15, A–U 2, A–B 4, A–T 14, N–U 17, N–B 5, N–T 13, U–B 8, U–T 6, B–T…