Concatenation of Array — LeetCode 1929 Python Solution

EasyArraySimulation
Problem
#1929
Reading time
2 min

The problem

Given an integer array nums of length n, you want to create an array ans of length 2n where ans[i] == nums[i] and ans[i + n] == nums[i] for 0 <= i < n (0-indexed). Specifically, ans is the concatenation of two nums arrays.

Example

Input
nums = [1,2,1]
Output
[1,2,1,1,2,1]
Explanation
The array ans is formed as follows:

Python solution

Python
class Solution:
    def getConcatenation(self, nums: List[int]) -> List[int]:
        return nums + nums

Complexity

MeasureComplexity
TimeO(n)
SpaceO(n) auxiliary

Related problems

Frequently asked questions

How hard is LeetCode 1929. Concatenation of Array?
LeetCode 1929. Concatenation of Array is rated Easy on LeetCode.
What is the time complexity of LeetCode 1929. Concatenation of Array?
The Python solution on this page runs in O(n).
What is the space complexity of LeetCode 1929. Concatenation of Array?
The Python solution on this page uses O(n) auxiliary space.
What topics does LeetCode 1929. Concatenation of Array cover?
LeetCode 1929. Concatenation of Array is tagged Array and Simulation on LeetCode.

Stuck on problems like this in a live interview?

Stealth Interview is a desktop app for macOS and Windows. It reads the problem off your screen and returns a working solution with a step-by-step explanation and its time and space complexity — invisible to screen sharing.

Get Stealth Interview