Data Structures & AlgorithmsModerateCodeforces Div 2 · ICPC regional
On an 6 × 6 chessboard with rows and columns numbered 0 to 5, a knight starts at (2, 5) and must reach (0, 0) (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. 7
- B. 4
- C. 5
- D. 3
Correct answer: D. 3
A BFS over knight moves gives 3; 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
- Complete undirected graph on vertices A to F with symmetric edge weights given row by row (row i, column j = weight of edge between…
- Bipartite graph with left side {A, B, C, D}, right side {E, F, G, H} and edges A–E, B–E, B–H, C–E, C–F, C–G, C–H, D–E. What is the size of…
- Distinct words ['bbba', 'aaa', 'bcaa', 'aac', 'b'] are inserted into an empty trie (one node per character, shared prefixes sharing nodes…
- A binary tree with distinct letters has preorder ACDEBF and inorder DEBCAF. What is its postorder traversal (left, right, root), written…
- Directed weighted graph on vertices B, F, A, C, D (source B, target D) with edges: B→F (2); B→A (5); A→F (-4); F→D (1); A→D (3); B→D (12)…
- Distinct words ['cc', 'aab', 'a', 'cbc', 'bbb', 'bc'] are inserted into an empty trie (one node per character, shared prefixes share…