FunctionRacerProblemsRace

Build Array from Permutation

BeginnerArraysPython, JavaScript, TypeScript, Java, C++

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

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Arrays problems