Search⌘ K
AI Features

Solution: Concatenation of Array

Understand how to build a concatenated array by tracking each index of the original array and placing elements at corresponding positions. This lesson helps you learn a linear time and space solution that efficiently duplicates an array without extra passes or built-in utilities.

Statement

Given an integer array nums of length n, construct an array ans of length 2n2n such that ans[i] == nums[i] and ans[i + n] == nums[i] for 00 \leq i << n (0-indexed).

In other words, ans is formed by appending nums to itself.

Return the array ans.

Constraints:

  • n ==== nums.length ...