Build Array from Permutation
nums contains each of the numbers 0 to len(nums) - 1 exactly once. Return a new list ans where ans[i] = nums[nums[i]] for every i.
Example 1
nums [0,2,1,5,3,4]
returns [0,1,2,4,5,3]
ans[1] = nums[nums[1]] = nums[2] = 1, and so on: [0, 1, 2, 4, 5, 3].
Constraints
1 <= len(nums) <= 30- Each of
0tolen(nums) - 1appears exactly once.
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Arrays problems
- Close NeighborsBeginner
- Concatenation of ArrayBeginner
- Deal Into PilesBeginner
- Decompress a Pair ListBeginner
- Find the Highest AltitudeBeginner
- Groups of KBeginner
- Items Within BudgetBeginner
- Kids With the Most CandiesBeginner