[Java] O(1) space beats 100 %
The index 0 and n - 1 never moves. So, if the index 1 reaches a index of power of 2 (2,4,8,16 etc) then it will come to back to 1 by subsequently dividing it by
The index 0 and n - 1 never moves. So, if the index 1 reaches a index of power of 2 (2,4,8,16 etc) then it will come to back to 1 by subsequently dividing it by 2 (power of 2 is always even) till we reach 1. It forms a cycle.\n\n```\nclass Solution \n{\n    public int reinitializePermutation(int n) \n    {   \n        int i = 1, steps = 0;\n        \n        do\n        {\n            steps++;\n            if(i % 2 == 0)\n                i >>= 1;\n            else\n                i = (n / 2) + ((i - 1) >> 1);\n        }while(i != 1);\n        \n        return steps;\n    }\n}\n```
[]