✅✅✅✅ Short & Simple Solution✅✅✅
Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem asks us to generate a list of n distinct positive integers ranging from 1 t
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem asks us to generate a list of n distinct positive integers ranging from 1 to n such that the absolute differences of all adjacent pairs in the list have exactly k distinct integers. One way to achieve this is by starting with the list [1, 2, ..., n] and performing a certain number of swaps between adjacent elements.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe can start with the list [1, 2, ..., n] and initialize two pointers, left and right, to 1 and n, respectively. Then, for each element of the answer list, we decide whether to pick the left or the right pointer, based on the value of k. If k > 1, we need to alternate between the two pointers in order to generate different absolute differences. If k == 1, we can simply use the left pointer for the remaining elements.\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nThe time complexity of this solution is O(n), since we need to iterate over all n elements of the answer list.\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nThe space complexity of the solution is O(n), since we need to store the entire list.\n# Code\n```\nimport java.util.*;\n\nclass Solution {\n    public int[] constructArray(int n, int k) {\n        int[] answer = new int[n];\n        int left = 1, right = n;\n        int i = 0;\n        while (i < n) {\n            if (k > 1) {\n                answer[i++] = (k % 2 == 0) ? right-- : left++;\n                k--;\n            } else {\n                answer[i++] = left++;\n            }\n        }\n        return answer;\n    }\n}\n\n```
['Array', 'Two Pointers', 'Greedy', 'Java']