Search⌘ K
AI Features

Solution: Concatenation of Array

Explore how to effectively track indices to solve the concatenation of array problem. Understand how to construct an output array by placing each element twice using a single pass, optimizing both time and space complexity.

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 ...