Simple Java solution O(n) with explanation
If the integer array ranging from 1 to n, the max possible diffenece is n-1. \n\tThat is, ans = [1, n, 2, n-1, ..., n/2].\n2. If we only want the result has exa
1. If the integer array ranging from ```1``` to ```n```, the max possible diffenece is ```n-1```. \n\tThat is, ```ans = [1, n, 2, n-1, ..., n/2]```.\n2. If we only want the result has exactly ```k``` distinct integer, the easiest way is to \n\t(1) Create an array from ```1``` to ```k+1``` which has max diffenece. \n\t(2) Attach the remaining numbers from ```k+2``` to ```n``` in the end of the result.\n\tThat is, ```ans = [1, k+1, 2, k, ..., k/2+1] + [k+2, k+3, ..., n]```.\n\n```\n    public int[] constructArray(int n, int k) {\n        int[] ans = new int[n];\n        // Create an array from 1 to n\n        for(int i = 0; i < n; i++) ans[i] = i+1;\n        // Let the first k+1 element has the max difference\n        for(int i = 0, j = 0; i <= k; j++) {\n            ans[i++] = j+1;\n            if(i <= k) ans[i++] = k-j+1;\n        }\n        return ans;\n    }\n```\nTime: O(n)
[]