Concatenation of Array

Concatenation of Array is a Easy Data Structures and Algorithms interview problem you can solve, run and submit on Thita.ai. It belongs to the Array/Matrix Manipulation Patterns pattern, in the In-place Rotation subpattern.

Problem statement

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

Topics and companies

Topics: Array, Iteration.

How to practise Concatenation of Array on Thita.ai

Starter code is provided in C#, C++, Go, Java, JavaScript and Python. Your solution runs against 5 test cases for this problem, with the AI coach available for a hint when you are stuck rather than a finished answer. The reference solution runs in O(n) time and O(n) space.

Open Concatenation of Array in the code editor, or read the Concatenation of Array editorial for a worked solution with its approach and complexity analysis.

Where Concatenation of Array sits in the DSA pattern sheet

Problems related to Concatenation of Array

Other problems that use the same In-place Rotation and Array/Matrix Manipulation Patterns techniques:

Opening the problem

Progress is saved as you study.