Data Structures & AlgorithmsHardGATE CS · ICPC regional
Grid with 3 rows and 3 columns (top to bottom). A cell marked G is a gate; '.' is a normal cell: .G. G.. ... Each step, which is a move to an adjacent cell or waiting one unit in place, takes exactly 1 time unit. A gate may only be occupied at an even time (t = 0, 2, 4, …); normal cells can be occupied at any time. You start at the top-left cell at time 0. What is the earliest time you can stand on the bottom-right cell?
- A. 4
- B. 6
- C. 7
- D. 5
Correct answer: D. 5
A BFS over (cell, time) states gives 5, since waiting is allowed and gates block odd arrival times. Ignoring gates gives 4, and forbidding waiting gives no answer.
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
- Two unmarked jugs hold 7 litres and 9 litres. Allowed operations: fill a jug completely, empty a jug completely, or pour one jug into the…
- A tree has vertices E, H, I, K, L, M, V, Z and weighted edges (weights in brackets): I–E (5), I–L (9), I–H (9), E–K (6), K–Z (7), E–M (1)…
- A directed acyclic graph has the vertices D, E, I, Q, R, U, Z and the edges D→R, D→E, Z→D, Z→R, Z→Q, Z→E, R→U, Q→D, I→D. A topological…
- A directed graph has the vertices H, J, M, T, X, Y and the arcs M→T, M→X, T→X, J→Y, X→Y, Y→T, Y→J. How many strongly connected components…
- A tree has the vertices D, E, I, L, O, P, Q, T, W and the edges T–D, D–L, L–Q, Q–E, T–I, E–O, T–P, D–W. A centroid is a vertex whose…
- The directed acyclic graph has the vertices E, H, J, K, S, T, V, W and the arcs W→E, S→K, J→H, V→H, J→K, V→W, W→K, E→H, J→T, T→E, V→S…