Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div 2
5 × 5 grid, rows top to bottom ('#' = wall, '.' = open): ..... / ###.. / ....# / ...## / ##.#.. Start at top-left, target bottom-right. Each move goes to one of the 4 neighbouring cells, and every time you step INTO a '#' cell it counts against a budget of 1 such entries in total. What is the minimum number of moves?
- A. 8
- B. 10
- C. no path
- D. 9
Correct answer: B. 10
A BFS over states (cell, wall-entries used) gives 10 moves; with no wall budget the route is no path. The Manhattan distance 8 is only a lower bound and ignores the walls.
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
- Points A(5,2), B(2,4), C(6,0), D(0,3), E(8,1) in the plane. The cost of joining two points is the Manhattan distance |x1−x2| + |y1−y2|…
- Undirected weighted graph on vertices A, B, C, D, E, F; its edges, in this listed order, are: B–D (8), A–E (3), C–D (8), A–C (3), C–F (4)…
- Directed weighted graph on vertices A, B, C, D, E with edges A→C (4); C→E (-2); D→C (-4); D→B (2); D→E (-1); D→A (1); E→D (6); E→C (-2)…
- Undirected simple graph on vertices A, B, C, D, E, F, G with edges A–B (1), A–E (1), A–G (1), B–C (1), B–F (1), B–G (1), C–F (1), C–G (1)…
- A chain of 6 matrices M1 to M6 has dimensions given by the sequence p = [20, 15, 18, 8, 2, 3, 20], where Mi has size p[i−1] × p[i]…
- Strings a = "bccbc" and b = "bbacaa". The edit distance allows insert, delete and substitute, each costing 1 (the standard Levenshtein…