Please share its tutorial.

Or explain how we would do it.

It is an application of Breadth First Search. BFS gives us the shortest paths The challenging aspect of the question is the way you store the state. Most of the solutions encode the state in a number. Ask if you need more help

Consider each state as a node, Let the two states be u and v. There will be a path between u and v if the state v is reachable from the state u. for example, consider the state u as

1 2 3

4 5 6

7 8 9

and the state v as

2 1 3

7 5 6

4 8 9

since we can reach state v from state u by interchanging 2 elements. therefore a path exists from u to v with the cost 2.

you need to find the shortest path from the given state to the goal state. use BFS to find the shortest distance from given state to the goal state.