Skip to content

Instantly share code, notes, and snippets.

@Ifihan
Created May 6, 2025 18:19
Show Gist options
  • Save Ifihan/50160336d1ee0cc96792d9f627cdb561 to your computer and use it in GitHub Desktop.
Save Ifihan/50160336d1ee0cc96792d9f627cdb561 to your computer and use it in GitHub Desktop.
Build Array from Permutation

Question

Approach

I used a simple list comprehension to construct the result array in a clean and efficient way.

Implementation

class Solution:
    def buildArray(self, nums: List[int]) -> List[int]:
        return [nums[nums[i]] for i in range(len(nums))]

Complexities

  • Time: O(n)
  • Space: O(n)
image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment