oneby7

Foundations Standard library

590. Concatenation of Array

Easy

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]

Output: [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]

Output: [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]

Output: [-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.

nums = [3, 0, 8]

Constraints

  • n == nums.length
  • 1 ≤ n ≤ 105
  • -109 ≤ nums[i] ≤ 109

Clarifying questions

What you would ask an interviewer before writing any code.

Hints

Interview follow-ups

Runs in your browser
Code
Runs in your browser for now · some things may not work as expectedLn 1, Col 1

Article

Send feedback

Thank you for helping. We read every report and fix what is wrong.

How do you feel about oneby7?

Sign in to oneby7

Keep your progress, your streak and your code, on any device.

New here? This creates your account too.