Sliding Tile Moves Problem
Sliding Tile Moves Problem — ExecCode Hard DSA Practice
Solve the Sliding Tile Moves problem on ExecCode. Free online hard DSA practice in Graph. Write and run code in Java, C++, Python — no signup required to run.
Problem description
A 2×3 sliding puzzle contains tiles 1–5 and a blank 0. A move slides a tile into the blank. The solved board is [[1,2,3],[4,5,0]]. This is a permutation-graph BFS used in Airbnb/Google OA hard questions. Return the fewest moves to solve the board, or -1 if unsolvable. You are given: board — 2 rows of 3 integers, a permutation of 0..5 Return integer moves or -1. You move the blank's neighbor into the blank, which is equivalent to moving the blank.
Examples
Input {'board': [[1, 2, 3], [4, 0, 5]]}; Output 1. Input {'board': [[1, 2, 3], [4, 5, 0]]}; Output 0. Input {'board': [[4, 1, 2], [5, 0, 3]]}; Output 5
Constraints
Exactly one blank Some permutations are unreachable
Practice Sliding Tile Moves free on ExecCode. Browse DSA problems, topic map, and placement guides.