Skip to main content

Concatenation of Array

Easy
Data Structures and Algorithms
Editorial
Topics:
Array
Iteration

Given an integer array nums, define its concatenation with itself as an array formed by placing all elements of nums first and then placing the same elements again in the same order.

Return the resulting integer array. The returned array must therefore contain two consecutive copies of nums, with the first copy unchanged and the second copy unchanged.

Example 1:

Input: nums = [7,2]
Output: [7,2,7,2]
Explanation: The original array [7, 2] is followed by an identical copy of itself.

Example 2:

Input: nums = [0]
Output: [0,0]
Explanation: A one-element array is repeated once, producing two occurrences of its only element.

Example 3:

Input: nums = [5,1,5]
Output: [5,1,5,5,1,5]
Explanation: The three elements appear in their original order, followed by the same three elements again.

Constraints:

  • 1 <= nums.length <= 1000
  • 1 <= nums[i] <= 1000
  • ``nums contains only integers

Need help or want more practice?

Practise in an interviewGet AI Coach help