Java || Array || 0ms || beats 100% || T.C - O(N) S.C - (N)
\n\n\t// O(n) O(n)\n\tpublic int[] constructArray(int n, int k) {\n\n\t\tint[] ans = new int[n];\n\t\tint small = 1, big = n, idx = 0;\n\n\t\tfor (int i = 0; i 
\n\n\t// O(n) O(n)\n\tpublic int[] constructArray(int n, int k) {\n\n\t\tint[] ans = new int[n];\n\t\tint small = 1, big = n, idx = 0;\n\n\t\tfor (int i = 0; i < k - 1; i += 2) {\n\t\t\tans[idx++] = small++;\n\t\t\tans[idx++] = big--;\n\t\t}\n\n\t\tint diff = n - k;\n\t\tif (k % 2 != 0) {\n\t\t\tfor (int i = 0; i <= diff; i++)\n\t\t\t\tans[idx++] = small++;\n\t\t} else {\n\t\t\tidx--;\n\t\t\tbig++;\n\t\t\tfor (int i = 0; i <= diff; i++)\n\t\t\t\tans[idx++] = big--;\n\t\t}\n\n\t\treturn ans;\n\t}\n
[]