Minimum Number of Operations to Reinitialize a Permutation LeetCode solution in Python

1
class Solution:
2
def reinitializePermutation(self, n: int) -> int:
3
ans = 0
4
perm = list(range(n))
5
while True:
6
ans += 1
7
perm = [
8
perm[n // 2 + (i - 1) // 2] if i & 1 else perm[i // 2] for i in range(n)
9
]
10
if all(perm[i] == i for i in range(n)):
11
return ans

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0