1806. Minimum Number of Operations to Reinitialize a Permutation Medium
1/**
2 * [1806] Minimum Number of Operations to Reinitialize a Permutation
3 *
4 * You are given an even integer n. You initially have a permutation perm of size n where perm[i] == i (0-indexed).
5 * In one operation, you will create a new array arr, and for each i:
6 *
7 * If i % 2 == 0, then arr[i] = perm[i / 2].
8 * If i % 2 == 1, then arr[i] = perm[n / 2 + (i - 1) / 2].
9 *
10 * You will then assign arr to perm.
11 * Return the minimum non-zero number of operations you need to perform on perm to return the permutation to its initial value.
12 *
13 * Example 1:
14 *
15 * Input: n = 2
16 * Output: 1
17 * Explanation: perm = [0,1] initially.
18 * After the 1^st operation, perm = [0,1]
19 * So it takes only 1 operation.
20 *
21 * Example 2:
22 *
23 * Input: n = 4
24 * Output: 2
25 * Explanation: perm = [0,1,2,3] initially.
26 * After the 1^st operation, perm = [0,2,1,3]
27 * After the 2^nd operation, perm = [0,1,2,3]
28 * So it takes only 2 operations.
29 *
30 * Example 3:
31 *
32 * Input: n = 6
33 * Output: 4
34 *
35 *
36 * Constraints:
37 *
38 * 2 <= n <= 1000
39 * n is even.
40 *
41 */
42pub struct Solution {}
43
44// problem: https://leetcode.com/problems/minimum-number-of-operations-to-reinitialize-a-permutation/
45// discuss: https://leetcode.com/problems/minimum-number-of-operations-to-reinitialize-a-permutation/discuss/?currentPage=1&orderBy=most_votes&query=
46
47// submission codes start here
48
49impl Solution {
50 pub fn reinitialize_permutation(n: i32) -> i32 {
51 0
52 }
53}
54
55// submission codes end
56
57#[cfg(test)]
58mod tests {
59 use super::*;
60
61 #[test]
62 fn test_1806() {
63 }
64}
65
Back
© 2025 bowen.ge All Rights Reserved.