Skip to content

Practice Minimum Number of Operations to Reinitialize a Permutation

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1806
LeetCode Problem

Minimum Number of Operations to Reinitialize a Permutation

Problem Statement

For even n, start with perm[i] = i for indices 0 through n - 1. In each operation build a new array: for even i set arr[i] = perm[i / 2]; for odd i set arr[i] = perm[n / 2 + (i - 1) / 2]. Replace perm with arr. Return the smallest positive number of operations that restores the initial permutation.

Source: Minimum Number of Operations to Reinitialize a Permutation on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 2
Output
1

# Example 2

Input
n = 4
Output
2

# Example 3

Input
n = 6
Output
4

Constraints

2 <= n <= 1000
n​​​​​​ is even.

Related LeetCode Problems

Practice more problems similar to Minimum Number of Operations to Reinitialize a Permutation.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.