1389. Create Target Array in the Given Order Easy

@problem@discussion
#Array#Simulation



1/**
2 * [1389] Create Target Array in the Given Order
3 *
4 * Given two arrays of integers nums and index. Your task is to create target array under the following rules:
5 * 
6 * 	Initially target array is empty.
7 * 	From left to right read nums[i] and index[i], insert at index index[i] the value nums[i] in target array.
8 * 	Repeat the previous step until there are no elements to read in nums and index.
9 * 
10 * Return the target array.
11 * It is guaranteed that the insertion operations will be valid.
12 *  
13 * Example 1:
14 * 
15 * Input: nums = [0,1,2,3,4], index = [0,1,2,2,1]
16 * Output: [0,4,1,3,2]
17 * Explanation:
18 * nums       index     target
19 * 0            0        [0]
20 * 1            1        [0,1]
21 * 2            2        [0,1,2]
22 * 3            2        [0,1,3,2]
23 * 4            1        [0,4,1,3,2]
24 * 
25 * Example 2:
26 * 
27 * Input: nums = [1,2,3,4,0], index = [0,1,2,3,0]
28 * Output: [0,1,2,3,4]
29 * Explanation:
30 * nums       index     target
31 * 1            0        [1]
32 * 2            1        [1,2]
33 * 3            2        [1,2,3]
34 * 4            3        [1,2,3,4]
35 * 0            0        [0,1,2,3,4]
36 * 
37 * Example 3:
38 * 
39 * Input: nums = [1], index = [0]
40 * Output: [1]
41 * 
42 *  
43 * Constraints:
44 * 
45 * 	1 <= nums.length, index.length <= 100
46 * 	nums.length == index.length
47 * 	0 <= nums[i] <= 100
48 * 	0 <= index[i] <= i
49 * 
50 */
51pub struct Solution {}
52
53// problem: https://leetcode.com/problems/create-target-array-in-the-given-order/
54// discuss: https://leetcode.com/problems/create-target-array-in-the-given-order/discuss/?currentPage=1&orderBy=most_votes&query=
55
56// submission codes start here
57
58impl Solution {
59    pub fn create_target_array(nums: Vec<i32>, index: Vec<i32>) -> Vec<i32> {
60        vec![]
61    }
62}
63
64// submission codes end
65
66#[cfg(test)]
67mod tests {
68    use super::*;
69
70    #[test]
71    fn test_1389() {
72    }
73}
74


Back
© 2025 bowen.ge All Rights Reserved.