Best C++ solution || Easy approach
Dry run the code and you can understand the logic. \n# Code\n\nclass Solution {\npublic:\n    vector<int> constructArray(int n, int k) {\n        vector<int> an
Dry run the code and you can understand the logic. \n# Code\n```\nclass Solution {\npublic:\n    vector<int> constructArray(int n, int k) {\n        vector<int> ans;\n        int i = 1, j = n;\n        while(i<=j)\n        {\n            if(k>1)\n                ans.push_back( (k--)%2 ? i++ : j--); \n            else\n                ans.push_back(i++);\n        }\n        return ans;\n    }\n};\n```
['C++']