01 · Question
Given nums of length n, return an array of length 2n containing nums twice: [nums, nums].
02 · Analysis
Allocate the result once, then fill both halves in the same loop:
- Write
nums[i]toans[i]. - Write the same value to
ans[i + n].
The point: use an index offset to map one input position to both output positions.
Complexity: time and output space, with auxiliary space.