Data Structures & AlgorithmsVery hardCodeforces Div 2 C · GATE CS
A grid has 7 rows and 8 columns (rows listed top to bottom; '.' is an open cell, '#' a wall): .......# ...#.... ..#..... .#.#.##. .#..#... ...#...# ##..#... Starting at the top-left cell, what is the minimum number of moves to reach the bottom-right cell, where a move goes to one of the four side-adjacent open cells?
- A. 13
- B. 15
- C. 7
- D. 16
Correct answer: B. 15
A BFS over open cells gives 15 moves, the detour forced by the walls. The Manhattan distance 13 ignores walls, and allowing diagonal moves gives 7.
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 8 litres. Allowed operations: fill a jug completely, empty a jug completely, or pour one jug into the…
- On an 6×6 chessboard, rows and columns are numbered 0 to 5, and squares are written (row, column). A knight moves in the usual L-shape…
- A four-wheel combination lock shows four digits 0–9 on wheels that wrap around (9 goes to 0 and 0 goes to 9). One move turns one wheel by…
- A flow network has source S and sink T, with directed arcs and capacities in brackets: S→D (1), S→B (6), C→B (9), D→A (9), D→T (8), B→D…
- A directed weighted graph has the arcs u→v (weight): Y→N (3), Y→E (9), Y→H (3), N→Y (3), N→E (4), N→H (7), E→N (15), E→A (11), H→Y (2)…
- An undirected graph has the vertices D, F, J, L, N, Y and the edges D–Y, Y–N, Y–J, N–F, F–J, J–L. In how many ways can each vertex be…