EasyNo. 1389
Create Target Array in the Given Order — LeetCode 1389 Python Solution
- Topics
- Array, Simulation
- 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
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
- Time
- O(n2)
- Space · auxiliary
- O(n)
Related problems
| No. | Problem | Difficulty |
|---|---|---|
| 0495 | Teemo Attacking | Easy |
| 0985 | Sum of Even Numbers After Queries | Medium |
| 1409 | Queries on a Permutation With Key | Medium |
| 1503 | Last Moment Before All Ants Fall Out of a Plank | Medium |
| 1535 | Find the Winner of an Array Game | Medium |
| 1560 | Most Visited Sector in a Circular Track | Easy |
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(n2).
- 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.