```
class Solution {
public int[] constructArray(int n, int k) {
int[] arr = new int[n];
arr[0]= 1;
int x=k, y=1;
for (int i=1; i<=k;i++){
arr[i] = arr[i-1] + x*y;
x--;
y=-y;
}
for (int i = k+1;i<n;i++){
arr[i]=i+1;
}
return arr;
}
}
```