# Minimum steps to sort array [closed]

Consider you have a permutation of $$1$$ to $$n$$ in an array $$array$$. Now select three distinct indices $$i$$,$$j$$,$$k$$, there is no need to be sorted. Let $$array_i$$, $$array_j$$ and $$array_k$$ be the values at those indices and now you make a right shift to it, that is $$new$$ $$array_i$$= $$old$$ $$array_j$$ and $$new$$ $$array_j$$= $$old$$ $$array_k$$ and $$new$$ $$array_k$$=$$old$$ $$array_i$$. Find the minimum number of operations required to sort the array or if is impossible how to determine it.

Example : Consider $$array= [3,1,2]$$; consider indices $$(1,3,2)$$ in the given order after applying one operation it is $$s =[1,3,2]$$.

• @Yuval Filmus can you suggest any algorithm? – user120540 May 3 '20 at 10:07
• By the way, applying the operation $(1,3,2)$ to the array $[3,1,2]$ gives the array $[2,3,1]$. If we instead applied $(1,2,3)$, we would get $[1,2,3]$. – Yuval Filmus May 3 '20 at 10:52
• The permutation $[3,1,2]$ is even. It's a 3-cycle. – Yuval Filmus May 3 '20 at 11:10
• Oh sorry ,and Thank you for the answer – user120540 May 3 '20 at 11:11
• This question appears to be about a problem from an ongoing contest. Please edit the question to clearly indicate the source of your problem. I will close this question for now while the source is unclear. We require you to attribute the source of all copied material. – D.W. May 3 '20 at 15:42