Data Structures & AlgorithmsVery hardCodeforces Div 2 · ICPC regional
2 × 3 sliding puzzle with tiles 1 to 5 and one blank (shown as _). Current board: 2 4 _ / 1 5 3. Goal board: 1 2 3 / 4 5 _. A move slides a tile that is orthogonally adjacent to the blank into the blank. What is the minimum number of moves to reach the goal?
- A. 7
- B. 4
- C. 11
- D. 5
Correct answer: A. 7
A BFS over all 360 reachable boards from the goal gives 7. Counting misplaced tiles or summing Manhattan distances are lower-bound heuristics, not the exact answer.
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
- Connected undirected graph on vertices A, B, C, D, E, F with edges A–C (1), A–F (1), B–D (1), C–D (1), C–F (1), D–E (1), D–F (1) (weights…
- Undirected weighted graph on vertices A, B, C, D, E with edges A–B (2), A–C (1), A–D (3), A–E (1), B–C (2), B–D (2), C–D (2). An edge is…
- Strings a = "baabbc" and b = "accca". The edit distance allows insert, delete and substitute, each costing 1 (the standard Levenshtein…
- Points A(5,7), B(2,4), C(3,8), D(5,0), E(1,1), F(9,8) in the plane. The cost of joining two points is the Manhattan distance |x1−x2| +…
- Directed weighted graph on vertices A, B, C, D, E with edges listed in this exact order: B→C (-3); D→A (-1); D→E (-2); A→E (6); B→A (-2)…
- Distinct words ['ba', 'c', 'b', 'ca', 'bc', 'aac'] are inserted into an empty trie (one node per character, shared prefixes share nodes…