Data Structures & AlgorithmsModerateCodeforces Div 2 · ICPC regional
On an 7 × 7 chessboard with rows and columns numbered 0 to 6, a knight starts at (0, 3) and must reach (5, 2) (as (row, column)). A knight move is the usual L shape (two in one direction and one perpendicular), and all squares are available. What is the minimum number of knight moves?
- A. 4
- B. 3
- C. 6
- D. 5
Correct answer: A. 4
A BFS over knight moves gives 4; the Chebyshev or Manhattan distance ignores the L-shape, which is why both are wrong.
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
- Distinct keys [27, 2, 19, 11, 24, 4] are inserted, in the order given by the sequence [24, 11, 4, 19, 2, 27], into an empty binary search…
- Undirected weighted graph on vertices A, B, C, D, E with edges A–B (2), A–D (2), A–E (1), B–D (3), B–E (2), C–E (1). An edge is CRITICAL…
- Distinct words ['aac', 'cb', 'ba', 'bc', 'a'] are inserted into an empty trie (one node per character, shared prefixes share nodes, and a…
- Undirected weighted graph on vertices A, B, C, D, E, F; its edges, in this listed order, are: C–F (2), B–D (2), D–E (7), B–C (9), D–F (2)…
- Directed weighted graph on vertices A, B, C, D, E with edges (u→v, w): C→A (8); D→E (2); B→A (9); E→D (1); B→D (1); A→E (1); E→A (9); A→B…
- Undirected weighted graph on vertices A, B, C, D, E, F with edges A–B (1), A–C (3), B–C (7), B–D (5), B–E (7), B–F (7), C–F (2), D–E (1)…