Java - beats 100% with explanation
Arrange first k+1 elements to obtain k different distinct numbers:\n\t  ex. For (k = 5, n = 9) the first 6 numbers will be: [1, 6, 2, 5, 3, 4]. This will result
1. Arrange first k+1 elements to obtain k different distinct numbers:\n\t  ex. For (k = 5, n = 9) the first 6 numbers will be: [1, 6, 2, 5, 3, 4]. This will result in 5 distinct integers: [5, 4, 3, 2, 1]\n2. For the rest of them (from k+1 to n), we can just add them to the result in increasing order which will give us 1 all the way.\n3. The final result will be for k=5, n=9 : [1, 6, 2, 5, 3, 4, 7, 8, 9]\n\n```\nclass Solution {\n    public int[] constructArray(int n, int k) {\n        int[] result = new int[n];\n        \n        int index = 0;\n        int x = 1, y = k+1;\n            \n        while (x <= y) {\n            result[index++] = x++;\n                \n            if (x < y) {\n                result[index++] = y--;\n            }\n        }\n        \n        for (int i=index+1; i<=n; i++) {\n            result[index++] = i;\n        }\n        \n        return result;\n    }\n}\n```
[]