Foundations Standard library
590. Concatenation of Array
You are given an array of integers nums of length n. Return an array of length 2n that holds all of
nums, followed by all of nums again.
The first n elements of the answer are the elements of nums in their order. The next n elements are the
same elements in the same order once more.
Example 1
Input: nums = [4, -2, 7]
[4,-2,7,4,-2,7]Explanation: The answer is [4, -2, 7] and then [4, -2, 7] again. The second copy starts at index 3, right after
the last element of the first.
Example 2
Input: nums = [5, 5, 0, 5]
[5,5,0,5,5,5,0,5]Explanation: Repeated values are copied like any others, so the answer is these four elements, then the same four again.
Example 3
Input: nums = [-1000000000]
[-1000000000,-1000000000]Explanation: With one element, the answer is that element twice.
Check your understanding
Work out the answer for this input before you write any code.
Constraints
n == nums.length1 ≤ n ≤ 105-109 ≤ nums[i] ≤ 109
Clarifying questions
What you would ask an interviewer before writing any code.