Not fast, but more explainable than original question! | Commented and Explained
Intuition\n Describe your first thoughts on how to solve this problem. \nOur goal is to get all numbers in range 1 to n+1 \nWe need them in a \'beautiful\' orde
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nOur goal is to get all numbers in range 1 to n+1 \nWe need them in a \'beautiful\' order \nTo start, we know we can get the beginning of an answer by going from 1 to n-k values \nSo, we start our answer there \nThen, we know that we want distint values in that range, and so we want to have the values marked when we have used them \nTo accomplish this, we can mark their availability \nWe build this by first marking all of our start answer components as False\nThen, we loop from where we stopped/1 to n+1 that those values are available. \n\nTo find our final answer we now do two steps \nFirst, we get our current value to consider as the last value of answer + 1 or just 1 if we have no answer built due to range considerations \nWe mark that as unavailable, and then add it to the answer \n\nWe can then loop over k from current to 0 and determine next updates as detailed in approach, before finally adding any missed values still available and then returning. \n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe get our original problem space with a list from 1 to n-k \nWe then set up values available and mark the original problem space considerations as unavailable \nWe then set up from our stopping point in original problem space to n+1 as available in our mapping \n\nWe select the current value based on either final of original problem space solution + 1 or 1 if no problem space set up yet \nMark it as unavailable and then add it to the answer \n\nNow while we have k > 1 \n- We could find an update at current value - k -> points to left end of range \n- Or we could find an update current value + k -> points to right end of range \n- If we have a value on left that is gt 0 and is available, we\'ll use that, otherwise we\'ll use the addition valuation \n- Once we know our next value, mark it\'s available status as false, set current value to it and update our answer \n- decrement k when done \n\nAt the end of the while loop, update answer with every value in value available we have not yet considered \n\nreturn when completed \n\nThis works by first eliminating the base case considered \nThen, does so by marking and udpates within range with consideration for which end of the \'total\' list we\'d be pulling from at any point \nThen finalizes with a final update for all unused values \n\n# Complexity\n- Time complexity : O(N + K) \n    - O(N) to build answer at start \n    - O(N) to build up value available \n    - O(N) to finalize value available \n    - O(K) to conduct while loop \n    - O(N) to finalize answer  \n\n- Space complexity : O(N) \n    - O(N) values stored  \n\n# Code\n```\nclass Solution :\n    def constructArray(self, n: int, k: int) -> List[int] :\n        # build array \n        answer = list(range(1, n-k))\n        # by first mapping if values are used or not \n        value_available = dict() \n        # mark initial considerations \n        for value in answer : \n            value_available[value] = False\n\n        # loop over values we may use \n        for value in range(min(1, n-k), n+1) : \n            # and since we have not used them, mark as True \n            value_available[value] = True\n        \n        # use either last value + 1 to start or 1 if no answer built yet \n        current_value = answer[-1]+1 if answer else 1 \n        value_available[current_value] = False\n        answer.append(current_value)\n\n        # loop while you have k to consider \n        while k > 1 : \n            # get subtraction by k and addition by k update \n            subtraction = current_value - k\n            addition    = current_value + k \n            # go with subtraction if subtraction is positive and we haven\'t used that value, otherwise addition \n            next_value = subtraction if (subtraction > 0 and value_available[subtraction]) else addition\n            # whatever it was, it\'s now not available \n            value_available[next_value] = False\n            # update current, add to answer and decrement k \n            current_value = next_value \n            answer.append(current_value)\n            k -= 1 \n\n        # add to answer all values still True for values in range we need and have not yet done\n        answer += [value for value in value_available.keys() if value_available[value] == True]\n        # return completed answer \n        return answer \n\n        \n```
['Python3']