Practice Create Target Array in the Given Order
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Begin with an empty target array. Read nums and index from left to right; at step i, insert nums[i] at position index[i], shifting existing elements at that position and later one place right. All insertions are valid. Return target after processing every element.
Source: Create Target Array in the Given Order on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
nums = [0,1,2,3,4], index = [0,1,2,2,1]
Output
[0,4,1,3,2]
# Example 2
Input
nums = [1,2,3,4,0], index = [0,1,2,3,0]
Output
[0,1,2,3,4]
# Example 3
Input
nums = [1], index = [0]
Output
[1]
Constraints
1 <= nums.length, index.length <= 100
nums.length == index.length
0 <= nums[i] <= 100
0 <= index[i] <= i
Related LeetCode Problems
Practice more problems similar to Create Target Array in the Given Order.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.