1 to 5 and one empty cell, written as 0. In one move you slide any tile that shares a side with the empty cell into it (that is, you swap 0 with an adjacent number).
The puzzle is solved when the frame reads [[1, 2, 3], [4, 5, 0]].
Given the current frame panel, return the smallest number of moves that solves it, or -1 if it cannot be solved.panel=[[1, 2, 3], [0, 4, 5]] → 2
Slide 4 to the left, then 5 to the left: 2 moves.
panel=[[2, 1, 3], [4, 5, 0]] → -1
No sequence of slides can swap just two tiles, so the answer is -1.
panel=[[1, 2, 3], [4, 5, 0]] → 0
The puzzle is already solved.
panel has 2 rows of 3 numberspanel are 0, 1, 2, 3, 4, 5, each exactly oncepanel=[[1, 2, 3], [0, 4, 5]]
2
Run checks the first 3 tests in your browser. Submit checks all 81 tests on the server, hidden ones included.