Create Target Array in the Given Order — LeetCode 1389 Python Solution
EasyArraySimulation
- Problem
- #1389
- Reading time
- 2 min
- Source
- leetcode.com
The problem
Given two arrays of integers nums and index. Your task is to create target array under the following rules: Initially target array is empty.
Example
- Input
- nums = [0,1,2,3,4], index = [0,1,2,2,1]
- Output
- [0,4,1,3,2]
- Explanation
- nums index target
Python solution
Python
class Solution:
def createTargetArray(self, nums: List[int], index: List[int]) -> List[int]:
target = []
for x, i in zip(nums, index):
target.insert(i, x)
return targetComplexity
| Measure | Complexity |
|---|---|
| Time | O(n^2) |
| Space | O(n) auxiliary |
Related problems
LeetCode 495Teemo AttackingEasyLeetCode 985Sum of Even Numbers After QueriesMediumLeetCode 1409Queries on a Permutation With KeyMediumLeetCode 1503Last Moment Before All Ants Fall Out of a PlankMediumLeetCode 1535Find the Winner of an Array GameMediumLeetCode 1560Most Visited Sector in a Circular TrackEasy
Frequently asked questions
- How hard is LeetCode 1389. Create Target Array in the Given Order?
- LeetCode 1389. Create Target Array in the Given Order is rated Easy on LeetCode.
- What is the time complexity of LeetCode 1389. Create Target Array in the Given Order?
- The Python solution on this page runs in O(n^2).
- What is the space complexity of LeetCode 1389. Create Target Array in the Given Order?
- The Python solution on this page uses O(n) auxiliary space.
- What topics does LeetCode 1389. Create Target Array in the Given Order cover?
- LeetCode 1389. Create Target Array in the Given Order is tagged Array and Simulation on LeetCode.