C++ greedy solution
\n// Runtime: 4 ms, faster than 63.20% of C++ online submissions for Beautiful Arrangement II.\n// Memory Usage: 7.8 MB, less than 28.80% of C++ online submissi
```\n// Runtime: 4 ms, faster than 63.20% of C++ online submissions for Beautiful Arrangement II.\n// Memory Usage: 7.8 MB, less than 28.80% of C++ online submissions for Beautiful Arrangement II.\nvector<int> constructArray(int n, int k) {\n\tvector<int> res {};\n\tint i = 1, j = n;\n\twhile (i <= j) {\n\t\tif (k > 0) {\n\t\t\tres.push_back(k-- % 2 ? i++ : j--);\n\t\t}\n\t\telse\n\t\t\tres.push_back(i++);\n\t}\n\treturn res;\n}\n```
['Greedy', 'C', 'C++']