C++ easy to understand,O(n)
\nclass Solution {\npublic:\n    vector<int> constructArray(int n, int k) {\n        vector<int> result(n, 0);\n        int sign = 1;\n        result[0] = 1;\n 
```\nclass Solution {\npublic:\n    vector<int> constructArray(int n, int k) {\n        vector<int> result(n, 0);\n        int sign = 1;\n        result[0] = 1;\n        for(int i = 1; i < n; i++) {\n            if(k == 0) {\n                result[i] = i + 1;\n                continue;\n            }\n            result[i] = result[i - 1] + k * sign;\n            sign *= -1;\n            k--;\n        }\n        return result;\n    }\n};\n```
[]