Data Structures & AlgorithmsHardCodeforces Div 2 C · GATE CS
Starting from the integer 4, 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 79?
- A. 7
- B. 8
- C. 75
- D. 6
Correct answer: D. 6
A BFS over the integers gives 6 operations. Peeling back from 79 with halving-when-even gives 8; using only +1 and doubling (no subtraction) needs 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 A, M, O, V and the arcs O→M, O→A, M→O, M→A, A→O, A→V, V→O, V→A. Count the directed Hamiltonian paths…
- An undirected graph has the vertices B, D, E, F, I, M, X and the edges M–E, M–X, M–D, M–B, M–F, E–X, E–D, E–I, X–D, X–B, D–F, B–I, F–I…
- A directed weighted graph has the arcs u→v (weight): Y→K (14), Y→Q (6), K→L (4), K→T (5), L→Q (8), D→Y (3), D→Q (11), D→T (3), Q→Y (12)…
- Each cell of a grid with 3 rows and 4 columns has an arrow: R = right, L = left, U = up, D = down. UURD DLRU LRUU From a cell you may move…
- A grid has 3 rows and 4 columns with these values (top to bottom): 4179 9341 9892 A path moves between side-adjacent cells (up, down, left…
- Two unmarked jugs hold 4 litres and 5 litres. Allowed operations: fill a jug completely, empty a jug completely, or pour one jug into the…