Input: A[] = {1, 3, 2}
Output: 2
Explanation: Let P[] = {7, 4, 2}.
After 1 operation, {P[1], P[3], P[2]} = {1, 2, 4}.
After 2 operations, {P[1], P[3], P[2]} = {7, 4, 2}
After 2 operation original array is reached.
Input: A[] = {5, 4, 2, 3, 1}
Output: 6
Explanation: Let P = {1, 2, 3, 4, 5},
After 1 operation {P[5], P[4], P[2], P[3], P[1]} = {5, 4, 2, 3, 1}
After 2 operation {P[5], P[4], P[2], P[3], P[1]} = {1, 3, 4, 2, 5}
After 3 operation {P[5], P[4], P[2], P[3], P[1]} = {5, 2, 3, 4, 1}
After 4 operation {P[5], P[4], P[2], P[3], P[1]} = {1, 4, 2, 3, 5}
After 5 operation {P[5], P[4], P[2], P[3], P[1]} = {5, 3, 4, 2, 1}
After 6 operation {P[5], P[4], P[2], P[3], P[1]} = {1, 2, 3, 4, 5}
After 6 operation original array is reached.
Below is the implementation of the approach.