[C++]Simple logical approach and code (100% faster solution & 75.5% space efficient then rest)
Approach - Lets keep the solution as simple as possible.So let us consider the k differences be 1,2,3,4.... upto k which would surely yeild a valid solution.\nN
**Approach** - Lets keep the solution as simple as possible.So let us consider the k differences be 1,2,3,4.... upto k which would surely yeild a valid solution.\nNow as k < n the only number which can be included in all valid adjacent differences is 1 (as if n= 8 and k = 7  only 1 and 8 can give that difference ).So we start constructing our ans from 1.\n\n**Code**\n```\nclass Solution {\npublic:\n    vector<int> constructArray(int n, int k) {\n        vector<int>a;\n\t\t//filling rest numbers which only constitute adjacent absolute differnce of 1 as k>=1\n        for(int i=n;i>k;i--)\n        {\n            a.push_back(i);\n        }\n\t\t//here the last element of a is k + 1 so start with a negative sign and alternate it for each value of k\n        bool sign = 0;\n        while(a.size()<n && k>0)\n        {\n            if(!sign)\n            {\n                a.push_back(a.back()-k);\n                sign = 1;\n            }\n            else a.push_back(a.back()+k),sign = 0;\n            k--;\n        }\n        return a;\n    }\n};\n```\n\nTime Complexity - O(n) one time linear iteration for all indexes.\nSpace Complexity - O(n) + k* O(1) = O(n)             //k is a constant.\n\nOpen for any suggestions/opinions...\n
['C', 'C++']