Detailed Explanation With Thought Process
First i tried to find the pattern. After taking example the question conveterd to\n\nImagine there is a infinite list and you are just tracking the index of  1.
First i tried to find the pattern. After taking example the question conveterd to\n\n`Imagine there is a infinite list and you are just tracking the index of  1. After how many repetation you find the `1` in the same position as it was in intial array i.e in index 1 . `\n\nAnd the position of 1 gets updated as 2,4,8....Why? Because you know in every reps, even index gets value from `[index/2] `.\n\nex -> in 1st rep `list[2] = list [1]`. in 2nd rep` list[4] = list[2]`  .And so on\n\nBut we don\'t have infinite list. So index gets wrap around (n-1).\nSo when again the index  is 1 we return our ans.\n\n```\nclass Solution {\n    public int reinitializePermutation(int n) {\n        int ans = 1;\n        int num = 2;\n        if(n == 2) return 1;\n        while(true){\n            if(num % (n-1) == 1)break; \n            else {\n                ans++;\n                num = (num * 2) % (n-1);\n            }\n        }\n        return ans;\n        \n    }\n}\n```\n\n\n\n
['Java']