package com.fishercoder.solutions;

import java.util.ArrayList;
import java.util.List;

/**
 * 1389. Create Target Array in the Given Order
 *
 * 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.
 *
 * Example 1:
 * Input: nums = [0,1,2,3,4], index = [0,1,2,2,1]
 * Output: [0,4,1,3,2]
 * Explanation:
 * nums       index     target
 * 0            0        [0]
 * 1            1        [0,1]
 * 2            2        [0,1,2]
 * 3            2        [0,1,3,2]
 * 4            1        [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]
 * Explanation:
 * nums       index     target
 * 1            0        [1]
 * 2            1        [1,2]
 * 3            2        [1,2,3]
 * 4            3        [1,2,3,4]
 * 0            0        [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
 * */
public class _1389 {
    public static class Solution1 {
        public int[] createTargetArray(int[] nums, int[] index) {
            List<Integer> list = new ArrayList<>();
            for (int i = 0; i < nums.length; i++) {
                list.add(index[i], nums[i]);
            }
            int[] target = new int[list.size()];
            for (int i = 0; i < target.length; i++) {
                target[i] = list.get(i);
            }
            return target;
        }
    }
}

@@ -85,1310 +85,8 @@
 t;%0A%0A
-/**%0A * 1389. Create Target Array in the Given Order%0A *%0A * Given two arrays of integers nums and index. Your task is to create target array under the following rules:%0A * Initially target array is empty.%0A * From left to right read nums%5Bi%5D and index%5Bi%5D, insert at index index%5Bi%5D the value nums%5Bi%5D in target array.%0A * Repeat the previous step until there are no elements to read in nums and index.%0A * Return the target array.%0A *%0A * It is guaranteed that the insertion operations will be valid.%0A *%0A * Example 1:%0A * Input: nums = %5B0,1,2,3,4%5D, index = %5B0,1,2,2,1%5D%0A * Output: %5B0,4,1,3,2%5D%0A * Explanation:%0A * nums       index     target%0A * 0            0        %5B0%5D%0A * 1            1        %5B0,1%5D%0A * 2            2        %5B0,1,2%5D%0A * 3            2        %5B0,1,3,2%5D%0A * 4            1        %5B0,4,1,3,2%5D%0A *%0A * Example 2:%0A * Input: nums = %5B1,2,3,4,0%5D, index = %5B0,1,2,3,0%5D%0A * Output: %5B0,1,2,3,4%5D%0A * Explanation:%0A * nums       index     target%0A * 1            0        %5B1%5D%0A * 2            1        %5B1,2%5D%0A * 3            2        %5B1,2,3%5D%0A * 4            3        %5B1,2,3,4%5D%0A * 0            0        %5B0,1,2,3,4%5D%0A *%0A * Example 3:%0A * Input: nums = %5B1%5D, index = %5B0%5D%0A * Output: %5B1%5D%0A *%0A * Constraints:%0A * 1 %3C= nums.length, index.length %3C= 100%0A * nums.length == index.length%0A * 0 %3C= nums%5Bi%5D %3C= 100%0A * 0 %3C= index%5Bi%5D %3C= i%0A * */%0A
 publ

add 1389