Java, easy to understand with explanation
1,n,2,n-1,3,n-2,4... ==> Diff:  n-1, n-2, n-3, n-4, n-5...\nBy following this pattern, k numbers will have k-1 distinct difference values; \nand all the rest nu
1,n,2,n-1,3,n-2,4... ==> Diff:  n-1, n-2, n-3, n-4, n-5...\nBy following this pattern, k numbers will have k-1 distinct difference values; \nand all the rest numbers should have |ai - a_i-1| = 1; \nIn total, we will have k-1+1 = k distinct values.\n\n```\nclass Solution {\n    public int[] constructArray(int n, int k) {\n        if(k>=n) return null;\n        int[] arr = new int[n];\n        int i = 0, small = 1, large = n;        \n        while(i<k){ \n            arr[i++] = small++;\n            if(i<k) arr[i++] = large--;\n        }        \n        if(k%2 == 0){ // k==2 ==> 1, 6, 5,4,3,2\n            while(i<arr.length) arr[i++] = large--;\n        } else { // k==3 ==> 1,6,2,3,4,5\n            while(i<arr.length) arr[i++] = small++;\n        }\n        return arr;\n    }\n}\n```
[]