Very Easy Approach|| fast || C++
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nWe have to just make a[
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe have to just make a[0] - a[1] = k. If it happens then keep on doing same and subrtact till k = 1. If k = 1, then simply push the remanining elements in ans vector.\n\nLet\'s take an example: \nn = 5, \n\nk = 3, 2, 1\nlow = 1 , 2\nhigh = n , 4, 3, 2\n\nans = 5, 1, 4, 3, 2\n\n    while(low <= high) { // 1<=5, 1<=4, 2<=4 2<=3, 2<=2, 2<=1{break the llo}\n        if(k % 2 == 0) { // 2%2==0, \n            ans.push_back(low); // 1\n                low++; // 2 \n            } else {// 3(odd), 1(odd), 1(odd)\n                ans.push_back(high); // 5, 4, 3, 2\n                high--; // 4, 3, 2, 1\n            }\n\n            if(k > 1) { // 3 > 2, 2 > 1 , 1 > 1 {k will remain same}\n                k--; // 2, 1\n            }\n        }\n\nJust print the result. Upvote if you like the approach\n    \n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nWe running till n and other opertation is O(1). So we can say in general, our code is taking O(n).\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nWe have created a vector<int> ans which holds exactly n elements so space complexity will be O(n).\n\n# Code\n```cpp []\nclass Solution {\npublic:\n\n    vector<int> constructArray(int n, int k) {\n        vector<int> ans;\n        \n        int low = 1, high = n; // n = 3\n\n        while(low <= high) { // 1 <= 3, 2 <= 3, 2 = 2\n            if(k % 2 == 0) { // k = 2 --> 2 % 2 = 0, 1 % 2 != 0 {odd}\n                ans.push_back(low); // 1\n                low++; // 2\n            } else {\n                ans.push_back(high); // 3 , 2\n                high--; // 2\n            }\n\n            if(k > 1) {\n                k--; // 1\n            }\n        }\n        \n        return ans;\n         \n    }\n};\n```
['C++']