Search
⌘K

Leetcode 1920. Build Array from Permutation

Given a zero-based permutation nums, return an array ans of the same length where ans[i] = nums[nums[i]] for every index i (i.e., compute the permutation composed with itself). The input guarantees distinct values 0..n-1 so indices are valid, and a follow-up asks for an in-place O(1) extra-space solution.


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Comments

Your account is free and you can post anonymously if you choose.