package leetcode;

/**
 * https://leetcode.com/problems/minimum-number-of-operations-to-reinitialize-a-permutation/
 */
public class Problem1806 {
    public int reinitializePermutation(int n) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1806 prob = new Problem1806();
        System.out.println(prob.reinitializePermutation(2)); // 1
        System.out.println(prob.reinitializePermutation(4)); // 2
        System.out.println(prob.reinitializePermutation(6)); // 4
    }
}

@@ -12,16 +12,42 @@
 tcode;%0A%0A
+import java.util.Arrays;%0A%0A
 /**%0A * h
@@ -226,329 +226,609 @@
     
-// TODO%0A        return 0;
+int%5B%5D initial = new int%5Bn%5D;%0A        for (int i = 0; i %3C n; i++) %7B
 %0A    
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem1806 prob = new Problem1806();%0A        System.out.println(prob.reinitializePermutation(2)); // 1%0A        System.out.println(prob.reinitializePermutation(4)); // 2%0A        System.out.println(prob.reinitializePermutation(6)); // 4
+    initial%5Bi%5D = i;%0A        %7D%0A        int answer = 0;%0A        int%5B%5D array = initial;%0A        while (true) %7B%0A            int%5B%5D tmp = new int%5Bn%5D;%0A            for (int i = 0; i %3C n; i++) %7B%0A                if (i %25 2 == 0) %7B%0A                    tmp%5Bi%5D = array%5Bi / 2%5D;%0A                %7D else %7B%0A                    tmp%5Bi%5D = array%5B(n / 2 + (i - 1) / 2)%5D;%0A                %7D%0A            %7D%0A            array = tmp;%0A            answer++;%0A            if (Arrays.equals(initial, tmp)) %7B%0A                return answer;%0A            %7D%0A        %7D
 %0A   

Solve problem 1806