Java solution with explanation
For the first k elements, we arrange in the following way:\n1, k + 1, 2, k, 3, k - 1, ....\n2. For the remaining elements, we set a[i] = i + 1, for i = k + 1, .
1. For the first k elements, we arrange in the following way:\n```1, k + 1, 2, k, 3, k - 1, ....```\n2. For the remaining elements, we set ```a[i] = i + 1```, for `i = k + 1, ....,n`\n\n```\nclass Solution {\n    public int[] constructArray(int n, int k) {\n        int[] res = new int[n];\n        for(int i = 0; i < k + 1; ++i) {\n            res[i] = (i % 2 == 0) ? i / 2 + 1 : k + 1 - (i - 1) / 2;\n        }\n        for(int i = k + 1; i < n; ++i) {\n            res[i] = i + 1;\n        }\n        return res;    \n    }\n}\n```
[]