""" 1389.1 - Solution 1 - Using List insert() """
#####################################################################################
# Imports
#####################################################################################
from typing import List
#####################################################################################
# Classes
#####################################################################################
class Solution:
"""Solution Class"""
def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:
"""Create Target Array Function"""
target = []
for i in range(len(nums)):
target.insert(index[i], nums[i])
return target
#####################################################################################
# Functions
#####################################################################################
def testcase():
"""Test Function"""
print(Solution().createTargetArray([0, 1, 2, 3, 4], [0, 1, 2, 2, 1]))
# Expected: [0, 4, 1, 3, 2]
print(Solution().createTargetArray([1, 2, 3, 4, 0], [0, 1, 2, 3, 0]))
# Expected: [0, 1, 2, 3, 4]
print(Solution().createTargetArray([1], [0]))
# Expected: [1]
#####################################################################################
# Main
#####################################################################################
if __name__ == "__main__":
testcase()
""" 1389.2 - Solution 2 - Using zip() """
#####################################################################################
# Imports
#####################################################################################
from typing import List
#####################################################################################
# Classes
#####################################################################################
class Solution:
"""Solution Class"""
def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:
"""Create Target Array Function"""
target = []
for n, i in zip(nums, index):
target.insert(i, n)
return target
#####################################################################################
# Functions
#####################################################################################
def testcase():
"""Test Function"""
print(Solution().createTargetArray([0, 1, 2, 3, 4], [0, 1, 2, 2, 1]))
# Expected: [0, 4, 1, 3, 2]
print(Solution().createTargetArray([1, 2, 3, 4, 0], [0, 1, 2, 3, 0]))
# Expected: [0, 1, 2, 3, 4]
print(Solution().createTargetArray([1], [0]))
# Expected: [1]
#####################################################################################
# Main
#####################################################################################
if __name__ == "__main__":
testcase()