1806. Minimum Number of Operations to Reinitialize a Permutation
On This Page
class Solution:
def reinitializePermutation(self, n: int) -> int:
res, i = 0, 1
while 1:
res += 1
if i < n >> 1:
i <<= 1
else:
i = (i - (n >> 1)) << 1 | 1
if i == 1:
return res