First loop for the unique differences...

Second loop for the remaining numbers with difference 1.

```
class Solution {
public int[] constructArray(int n, int k) {
int[] out=new int[n];
out[0]=1;
boolean up=true;
k++;
int c=k+1;
int i=1;
while(--k>0){
if(up) out[i]=out[i-1]+k;
else out[i]=out[i-1]-k;
i++;
up=!up;
}
while(c<=n){
out[i++]=c++;
}
return out;
}
}
```