Tap here to switch tabs
Problem
Submissions

Problem: Minimum Operations to Reinitialize a Permutation

med
30 min
Try to solve the Minimum Operations to Reinitialize a Permutation problem.

Statement

You are given an even integer n. Initially, you have a permutation perm of size n where perm[i] is equal to i for each 0 \le i < n (00 indexed).

In each step, you create a new array arr of size n defined as follows:

  • If i % 2 == 0, then arr[i] = perm[i / 2]

  • If i % 2 == 1, then arr[i] = perm[n / 2 + (i - 1) / 2]

You then assign arr to perm.

Return the minimum non-zero number of operations required to return the permutation perm back to its initial configuration.

Constraints:

  • 2≤2 \le n ≤1000\le 1000

  • n is even.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Operations to Reinitialize a Permutation

med
30 min
Try to solve the Minimum Operations to Reinitialize a Permutation problem.

Statement

You are given an even integer n. Initially, you have a permutation perm of size n where perm[i] is equal to i for each 0 \le i < n (00 indexed).

In each step, you create a new array arr of size n defined as follows:

  • If i % 2 == 0, then arr[i] = perm[i / 2]

  • If i % 2 == 1, then arr[i] = perm[n / 2 + (i - 1) / 2]

You then assign arr to perm.

Return the minimum non-zero number of operations required to return the permutation perm back to its initial configuration.

Constraints:

  • 2≤2 \le n ≤1000\le 1000

  • n is even.