package leetcode;

/**
 * https://leetcode.com/problems/beautiful-arrangement-ii/
 */
public class Problem667 {
    public int[] constructArray(int n, int k) {
        // TODO
        return null;
    }

    public static void main(String[] args) {
        Problem667 prob = new Problem667();
        System.out.println(prob.constructArray(3, 1)); // [1,2,3]
        System.out.println(prob.constructArray(3, 2)); // [1,3,2]
        System.out.println(prob.constructArray(10, 9)); // [1,10,2,9,3,8,4,7,5,6]
        System.out.println(prob.constructArray(10, 5)); // [1,6,2,5,3,4,7,8,9,10]
    }
}

@@ -12,16 +12,42 @@
 tcode;%0A%0A
+import java.util.Arrays;%0A%0A
 /**%0A * h
@@ -191,35 +191,531 @@
     
-// TODO%0A        return null
+int%5B%5D result = new int%5Bn%5D;%0A        int idx = 0;%0A        for (int i = 0; i %3C n; i++) %7B%0A            if (i == 0) %7B%0A                result%5Bidx++%5D = i + 1;%0A                continue;%0A            %7D%0A            if (k %3E 0) %7B%0A                int a = result%5Bi - 1%5D - k;%0A                if (a %3C= 0) %7B%0A                    a = result%5Bi - 1%5D + k;%0A                %7D%0A                result%5Bidx++%5D = a;%0A                k--;%0A            %7D else %7B%0A                result%5Bidx++%5D = result%5Bi - 1%5D + 1;%0A            %7D%0A        %7D%0A        return result
 ;%0A  
@@ -827,32 +827,48 @@
 tem.out.println(
+Arrays.toString(
 prob.constructAr
@@ -877,16 +877,17 @@
 y(3, 1))
+)
 ; // %5B1,
@@ -910,32 +910,48 @@
 tem.out.println(
+Arrays.toString(
 prob.constructAr
@@ -960,16 +960,17 @@
 y(3, 2))
+)
 ; // %5B1,
@@ -993,32 +993,48 @@
 tem.out.println(
+Arrays.toString(
 prob.constructAr
@@ -1044,16 +1044,17 @@
 (10, 9))
+)
 ; // %5B1,
@@ -1100,16 +1100,32 @@
 println(
+Arrays.toString(
 prob.con
@@ -1143,16 +1143,17 @@
 (10, 5))
+)
 ; // %5B1,

Update problem 667