In "The Game of Eight", you are given a 3x3 board containing 8 squares labelled 1 through 8, and one empty space. The initial state of the board is given in the String[] board, where '.' represents the empty space. In each turn, you pick any square which is horizontally or vertically adjacent to an empty space and move it to the empty space (see example 0 for clarification).
Your goal is to arrange the squares so the board looks like this:
{"123",
"456",
"78."}
Return the minimum number of moves necessary to achieve this goal, or -1 if it's impossible.
|