Beautiful Arrangement II
Complexity
Time complexity: O(N)

Space complexity: O(1)
Code


# Complexity
- Time complexity: O(N)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: O(1)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```python []
class Solution(object):
    def constructArray(self, n, k):
        """
        :type n: int
        :type k: int
        :rtype: List[int]
        """
        res = []
        left, right = 1, n
        
        while k > 0:
            if k % 2 == 1:
                res.append(left)
                left += 1
            else:
                res.append(right)
                right -= 1
            k -= 1
        
        if len(res) < n:
            res.extend(range(left, right + 1))
        
        return res

```
['Array', 'Math', 'Python']