Simple Java Solution (Beats 96.46%)
Intuition\nPattern for first k position is { n , arr[i-1]-(n-i) , arr[i-1]+(n-i) , arr[i-1]-(n-i)......... and so on }\n\nPattern after k postion is (arr[i-1] +
# Intuition\nPattern for first k position is { n , arr[i-1]-(n-i) , arr[i-1]+(n-i) , arr[i-1]-(n-i)......... and so on }\n\nPattern after k postion is (arr[i-1] +/- 1) , depending whether the last position was a addition or subtraction\n\n# Complexity\n- Time complexity:\nO(n)\n- Space complexity:\nO(n)\n# Code\n```\nclass Solution {\n    public int[] constructArray(int n, int k) {\n\n        int num=-1;\n        int[] res = new int[n];\n        res[0]=n;\n        for(int i=1;i<n;i++){\n            if(i<k){\n                if(num>0){    \n                    res[i]=res[i-1]+(n-i);\n                    num*=-1;\n                }else{\n                    res[i]=res[i-1]-(n-i);\n                    num*=-1;\n                }\n            }else{\n                res[i]=res[i-1]+num;\n            }\n        }\n\n        return res;\n\n    }\n}\n```
['Array', 'Java']