C++ 100% O(1) space
Intuition\n Describe your first thoughts on how to solve this problem. \nWe just need to check one index (not 0 or n - 1 as they don\'t change all the time), an
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe just need to check one index (not 0 or n - 1 as they don\'t change all the time), any index should work, when it turns to the original value again, the permutation returns to the initial state.\n\nIn the solution, we use index 1.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nint reinitializePermutation(int n) {\n    int ans = 0, x = 1;\n    do {\n        x = (x % 2) ? n/2 + (x - 1)/2 : x/2;\n        ans++;\n    } while (x != 1);\n    return ans;\n}\n```
['C++']