#1389
Easy Algorithms Create target array in the given order
Array Simulation
86.5% acceptance
Feb 25, 2026
2283
1916
Given two arrays of integers nums and index. Your task is to create target array under the following rules:
Initially target array is empty.
From left to right read nums[i] and index[i], insert at index index[i] the value nums[i] in target array.
Repeat the previous step until there are no elements to read in nums and index.
Return the target array.
It is guaranteed that the insertion operations will be valid.
Solution
Rust
Time O(n)
Space O(n)
impl Solution {
pub fn create_target_array(nums: Vec<i32>, index: Vec<i32>) -> Vec<i32> {
let mut target: Vec<i32> = Vec::new();
for (n, i) in nums.into_iter().zip(index.into_iter()) {
target.insert(i as usize, n);
}
target
}
}