java 100%faster 98%less memory
\nclass Solution {\n    public int[] constructArray(int n, int k) {\n        int[] res = new int[n];\n        int left = 1, right = k + 1, i = 0;\n        while
```\nclass Solution {\n    public int[] constructArray(int n, int k) {\n        int[] res = new int[n];\n        int left = 1, right = k + 1, i = 0;\n        while (left < right) {\n            res[i++] = left++;\n            res[i++] = right--;\n        }\n        if (left == right) res[i++] = left;\n        while (i < n) res[i++] = i;\n        return res;\n    }\n}\n```
[]