clean and intuitive greedy approach
consider \n\n1,2,3,4,5\n\nhere you can see that the number of unique differences is 1\n\nconsider \n\n5 1 2 4 3\n\nhere the number of unique difference is n-1\n
consider \n\n1,2,3,4,5\n\nhere you can see that the number of unique differences is 1\n\nconsider \n\n5 1 2 4 3\n\nhere the number of unique difference is n-1\n\nwell these two examples give a big hint\n\ntill k>1, everytime make a new diferrence\n\nthen simply use the the digits to make a difference of exact 1\n\ndry run to understand better\n\n# Code\n```\nclass Solution {\n    public int[] constructArray(int n, int k) {\n        return util1(n,k);\n    }\n    public int[] util1(int n, int k) {\n        int left = 1, right = n;\n        int ans[] = new int[n];\n        int a = 0;\n        while (k != 1) {\n            if (a % 2 == 0) {\n                ans[a] = right;\n                right--;\n            } else {\n                ans[a] = left;\n                left++;\n            }\n            a++;\n            k--;\n        }\n\n        if (a % 2 == 0) {\n            while (right >= left) {\n                ans[a] = right;\n                right--;\n                a++;\n            }\n        } else {\n            while (right >= left) {\n                ans[a] = left;\n                left++;\n                a++;\n            }\n        }\n        return ans;\n    }\n}\n```\nyou can check out my github repository where i am uploading famous interview questions topic wise with solutions.\nlink-- https://github.com/Abhaydutt2003/DataStructureAndAlgoPractice \nkindly upvote if you like my solution. you can ask doubts below.\n    \n
['Greedy', 'Java']