Solution
C++ []\nclass Solution {\npublic:\n    vector<int> constructArray(int n, int k) {\n        vector<int> ans;\n        int i;\n        for(i = 1; i <= n - k; i++)
```C++ []\nclass Solution {\npublic:\n    vector<int> constructArray(int n, int k) {\n        vector<int> ans;\n        int i;\n        for(i = 1; i <= n - k; i++)\n        {\n            ans.push_back(i);\n        }\n        int count = 0;\n        for(int j = 0; j < k; j++)\n        {\n            if(j%2==0)\n            ans.push_back(n-count), count++;\n            else ans.push_back(i), i++;\n        }\n        return ans;\n    }\n};\n```\n\n```Python3 []\nclass Solution:\n    def constructArray(self, n: int, k: int) -> List[int]:\n\n        ans = list(range(1, n - k)) \n        for i in range(k+1):\n            if i % 2 == 0:\n                ans.append(n-k + i//2)\n            else:\n                ans.append(n - i//2)\n\n        return ans\n```\n\n```Java []\nclass Solution {\n    public int[] constructArray(int n, int k) {\n        int ans[]=new int[n];\n        int low=1,high=n,index=0;\n        boolean isHigh=false;\n        ans[index++]=low++;\n        while(k>1){\n            ans[index++]=high--;\n            k--;\n            isHigh=true;\n            if(k>1){\n                ans[index++]=low++;\n                k--;\n                isHigh=false;\n            }\n        }\n        while(index<n){\n            if(isHigh) ans[index++]=high--;\n            else ans[index++]=low++;\n        }\n        return ans;\n    }\n}\n```\n
['C++', 'Java', 'Python3']