Data Structures & AlgorithmsHardGATE CS · ICPC regional
Grid with 3 rows and 4 columns (top to bottom). A cell marked G is a gate; '.' is a normal cell: .G.G 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. 5
- B. 10
- C. 11
- D. 6
Correct answer: D. 6
BFS over (cell, time parity) states, with waiting allowed, gives 6: a gate can only be entered at an even time, so one wait is needed. Ignoring the gate rule gives the plain shortest path 5; waiting after every move gives 10, and 11 visits every cell.
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
- Starting from the integer 6, one operation either adds 1, subtracts 1, or doubles the current value. Values may be any non-negative…
- A connected undirected graph has the vertices D, L, Q, R, T, Y and the edges Y–D, Y–T, D–Q, D–R, D–L, R–T, R–L, T–L. Parallel edges are…
- A bipartite graph has left side P1, P2, P3, P4 and right side Q1, Q2, Q3, with edges P4–Q2, P3–Q3, P4–Q3, P1–Q3, P2–Q1, P4–Q1. What is the…
- Consider this recursive function: python def f(n): if n <= 1: return f(n - 2) if n % 2 == 0: f(n - 3) How many times is f called in total…
- An undirected graph has the vertices E, G, I, L and the edges G–I, G–E, I–L, L–E. A walk may repeat vertices and edges. How many walks of…
- A directed acyclic graph has the vertices D, F, I, P, R, X, Y and the directed edges I→F, Y→F, R→P, X→P, Y→D, D→P, X→D, R→F, Y→X. How many…