Build Array from Permutation Problem
Build Array from Permutation Problem — ExecCode Easy DSA Practice
Solve the Build Array from Permutation problem on ExecCode. Free online easy DSA practice in Arrays - Logic Building. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Description You are given a zero-based permutation nums (0-indexed), build an array ans of the same length where ans[i] = nums[nums[i]] for each 0 <= i < nums.length and return it. Your task is to a zero-based permutation nums is an array of distinct integers from 0 to nums.length - 1 (inclusive). Return the required answer exactly as shown in the examples.
Examples
Input {"nums": [0, 2, 1, 5, 3, 4]}; Output [0, 1, 2, 4, 5, 3]. Input {"nums": [5, 0, 1, 2, 3, 4]}; Output [4, 5, 0, 1, 2, 3]
Constraints
1 <= nums.length <= 1000 0 <= nums[i] < nums.length The elements in nums are distinct.
Practice Build Array from Permutation free on ExecCode. Browse DSA problems, topic map, and placement guides.