help needed for beginner problem "H1"

i need to solve codechef beginner section practise question “H1” can someone please comment me a solution code written in c++?? thanks in advanced.

I think copy-pasting the code is the easiest solution but not the best. If you want any help about a problem in Your code I will be glad to support.

Idk one thing… Why u need code ? Why you don’t need explanation… Writing code should be completely done by you…

Can you explain me the logic then ?

I think you should try to memorize every 3x3 input in a matrix (you can use only one) and then, using a temporary matrix, code the algorithm to check for every possible swap that follows the given rule.

how to avoid infinite loops ?? Isn’t it possible that only one move is possible and it keeps going on and on…

You can use flags to stop the loop if it has swapped a number back in the starting position