Easy To Understand || O(n) || C++ || TWO POINTER
class Solution {\npublic:\n    vector constructArray(int n, int k) {\n        \n        vector a(n,0);\n        \n        int i,j;\n        for(i=0;i res(n,0);\
class Solution {\npublic:\n    vector<int> constructArray(int n, int k) {\n        \n        vector<int> a(n,0);\n        \n        int i,j;\n        for(i=0;i<n;i++)\n            a[i] = i+1;\n        \n        if(k==1)\n            return a;\n        \n        i=0;j=n-1;\n        \n        vector<int> res(n,0);\n        \n        int ind=0;\n        int t=0; // insert from back  , t=1 -> inset from front\n        \n        while(k--){\n            \n            if(t==0)\n             res[ind++] = a[j--];\n            else\n                res[ind++] = a[i++];\n            \n            t=t^1;\n        }\n        \n        if(t){\n            while(j>=i && j>=0)\n                res[ind++] = a[j--];\n        }\n        else{\n            while(i<=j && i<n)\n                res[ind++] = a[i++];\n        }\n        \n        return res;\n    }\n};
['Two Pointers']