Java solution. Easy to understand explanation
We have 2 cases:\n\n1. k is 1 , this means that the only possible difference between 2 consecutive numbers is 1, so the answer is the array of consecutive numbe
We have 2 cases:\n\n1. k is 1 , this means that the only possible difference between 2 consecutive numbers is 1, so the answer is the array of consecutive numbers between 1 and n: [1,2,...,n]\n2. k is greater than 1, this means we have to create k different differences in our array.\n   The easiest way to do that is by creating 2 auxiliary numbers that will help us assign values in our array. At start, these 2 values are 1 and n. The idea is that for the even indexes we assign the lower value that increments at every even index, and for the odd indexes we assign the higher value that decrements at every odd index. By doing that, we make sure that the difference is always different between 2 consecutive numbers because it decrements at every index through the iteration. Here\'s how:\n\tindex 0: 1\n    index 1: n, the difference is n-1\n   index 2: 2 (even index, so we increment), the difference is n-2\n   index 3: n-1 (odd index, so we decrement), the difference is n-3.... and so on\n   When we reach k-1 different differences, we stop the method above. The k-th different difference is 1, so that we can put in the array the unassigned values from the [1...n] interval. Depending on where we left the array, we start iterating and assign the rest of the array, decrementing if we left the array on an odd index, or incrementing if we left the array on an even index.\n   \n  ```\n public int[] constructArray(int n, int k) {\n        int[] rez=new int[n];\n        if(k==1){\n            for(int i=0;i<n;i++){\n                rez[i]=i+1;\n            }\n            return rez;\n        }\n        int k1=2;\n        int k2=n;\n        int nr=0;\n        rez[0]=1;\n        int i=1;\n        while(i<n){\n            if(i%2==0){\n                rez[i]=k1;\n                k1++;\n            }\n            else{\n                rez[i]=k2;\n                k2--;\n            }\n            nr++;\n            if(nr==k-1){\n                break;\n            }\n            i++;\n        }\n        if(i%2==0){\n            i++;\n            while(i<n){\n                rez[i]=rez[i-1]+1;\n                i++;\n            }\n        }\n        else{\n            i++;\n            while(i<n){\n                rez[i]=rez[i-1]-1;\n                i++;\n            }\n        }\n        return rez;\n    }\n```
[]