N cubes placed side by side like the above picture. I have to Correct vertex numbering is shown in picture. From left to right, every face is numbered in counter-clockwise order. So first face has number 1-2-3-4, second face 5-6-7-8 and so on. So if N cubes are placed then, there are 4*(N+1) numbers (1 to 4N + 4).
Now initially the numbers are placed in random order. I have to make them correct order. To bring them in correct order, I can only swap 1 and an adjacent number of 1
For example, in the above diagram, we can swap (1, 8) and then (1, 5) to bring it into correct form.
Given, N-1(<=40) at input and number currently at 1, number currently at 2, … number currently at 4*N. I have to find out minimum number of moves
So if I have given the following input :
5 2 3 4 8 6 7 1
I have to output 2 .
I have tried several times to solve this problem but failed . Guyz , can you help me in this regard ?