Array | Math | C++ | TC[<O(n)] | SC[O(1)]
Intuitionwe have initial permutation as perm[i]=i and we look at the position of each element after appling operations.
let : n=6
initial perm : [0,1,2,3,4,5]
a
# Intuition
we have initial permutation as perm[i]=i and we look at the position of each element after appling operations.
let : n=6
initial perm : [0,1,2,3,4,5]
after first operation : 
 arr : [0,2,4,1,3,5]
 perm = arr => perm =[0,2,4,1,3,5]

after second operation : 
 arr : [0,4,3,2,1,5]
 perm : [0,4,3,2,1,5]

after third operation : 
 arr : [0,3,1,4,2,5]
 perm : [0,3,1,4,2,5]

after Fourth operation :
 perm : [0,1,2,3,4,5]

if we see the position changing of element of 1.(1->3->4->2->1)
after first ops position of 1's is (n/2)th after this is change position according to given in description till element 1 not reached at initial position(i=1);

# Complexity
- Time complexity: ~= O(n/2) 

- Space complexity: O(1)
# Code
```cpp []
class Solution {
public:
    int reinitializePermutation(int n) {
        int cntPermutation=0;
        int pos=n/2;
        cntPermutation++;
        while(pos!=1){
            cntPermutation++;
            if(pos%2==1){
                pos=(n/2 + (pos-1)/2);
            }
            else{
                pos/=2;
            }
        } 
        return cntPermutation ;
    }
};
```
['C++']