Tap here to switch tabs
Problem
Submissions

Problem: Build Array from Permutation

med
30 min
Try to solve the Build Array from Permutation problem.

Statement

Given a zero-based permutation nums, construct an array ans of the same length such that, ans[i] = nums[nums[i]] for every valid index i.

Return the constructed array ans.

A zero-based permutation is an array of distinct integers from 0 to nums.length - 1, inclusive.

Constraints:

  • 11 \leq nums.length 103\leq 10^3

  • 00 \leq nums[i] << nums.length

  • All elements in nums are distinct.

Unlock AI-Powered LearningUpgrade to smarter learning with instant explanations of Ask Agent, Personalized Interview Prep, Real-World Projects, 3 AI Mock Interviews per month, and Personalized Paths
Tap here to switch tabs
Problem
Submissions

Problem: Build Array from Permutation

med
30 min
Try to solve the Build Array from Permutation problem.

Statement

Given a zero-based permutation nums, construct an array ans of the same length such that, ans[i] = nums[nums[i]] for every valid index i.

Return the constructed array ans.

A zero-based permutation is an array of distinct integers from 0 to nums.length - 1, inclusive.

Constraints:

  • 11 \leq nums.length 103\leq 10^3

  • 00 \leq nums[i] << nums.length

  • All elements in nums are distinct.

Unlock AI-Powered LearningUpgrade to smarter learning with instant explanations of Ask Agent, Personalized Interview Prep, Real-World Projects, 3 AI Mock Interviews per month, and Personalized Paths