TypeScript solution - runtime beats 100%, memory beats 100%
\n# Code\n\nfunction reinitializePermutation(n: number): number {\n  const initialPerm = Array.from(Array(n).keys())\n\n  let perm = initialPerm\n\n  const muta
\n# Code\n```\nfunction reinitializePermutation(n: number): number {\n  const initialPerm = Array.from(Array(n).keys())\n\n  let perm = initialPerm\n\n  const mutate = () => {\n    let arr = []\n\n    for (let i = 0; i < n; i++) {\n      if (i % 2 === 0) {\n        arr.push(perm[i / 2])\n      } else {\n        arr.push(perm[n / 2 + (i - 1) / 2])\n      }\n    }\n\n    perm = arr\n    return arr\n  }\n\n  let count = 1\n\n  while (mutate().join(\',\') !== initialPerm.join(\',\')) {\n    count++\n  }\n\n  return count\n};\n```
['TypeScript', 'JavaScript']