Intern — Middle
Creating an array containing two consecutive copies of the original list
livecode
Task condition
Given an array arr of length n. It is necessary to form an array result of length 2·n, in which all elements of arr come first, followed by their copy in the same order.
Example 1: Input: arr = [1,2,1] Output: [1,2,1,1,2,1] Explanation: The result array is formed as follows:
- result = [arr[0], arr[1], arr[2], arr[0], arr[1], arr[2]]
- result = [1,2,1,1,2,1]
Example 2: Input: arr = [1,3,2,1] Output: [1,3,2,1,1,3,2,1] Explanation: result = [arr[0], arr[1], arr[2], arr[3], arr[0], arr[1], arr[2], arr[3]]
- result = [1,3,2,1,1,3,2,1]