Best c++ Code Beast 100%
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    vector<int> constructArray(int n, int k) {\n        vector<int> v;\n        //Insert 1 => This is the base for creating the rest of the array\n        v.push_back(1);\n        int maxi = k;\n        int flag = 1; //1->increase, 0->decrease\n        while(v.size()<n && maxi){\n            //increase\n            if(flag){\n                int nextNum = v.back() + maxi;\n                v.push_back(nextNum);\n                maxi--;\n            }\n            //decrease\n            else{\n                int nextNum = v.back() - maxi;\n                v.push_back(nextNum);\n                maxi--;\n            }\n            flag = !flag;\n        }\n        //If maxi = 0 => Elements will repeat, push the left out elements after the maximum in ans\n        int i = *max_element(v.begin(),v.end());\n        i++;\n        while(v.size()<n){\n            v.push_back(i);\n            i++;\n        }\n        return v;\n    }\n};\n```
['C++']