File: concatenation-of-array/solution.py

Date: 2026-06-06

Time: 15:47

concatenation-of-array/solution.py

Purpose

This file implements the solution to LeetCode 1929 - Concatenation of Array. Given an integer array nums of length n, it returns an array ans of length 2n where ans[i] == nums[i] and ans[i + n] == nums[i] — effectively nums appended to itself.

Key Components

Solution.maxValue — The method name is wrong. It should be getConcatenation per the LeetCode problem signature. The docstring correctly describes the concatenation behavior, but the method name suggests a different problem (likely a copy-paste error from another solution). Despite the naming bug, the implementation itself is correct: nums + nums produces the right output.

The implementation uses Python's list concatenation operator (+), which creates a new list containing all elements of the left operand followed by all elements of the right. This runs in O(n) time and O(n) space.

Patterns

Dependencies

Flow

1. Caller instantiates Solution() and calls maxValue(nums).

2. Python evaluates nums + nums, allocating a new list of length 2n and copying elements from nums twice.

3. The new list is returned.

No branching, no loops, no mutation of the input.

Invariants

Error Handling

None. The function trusts the caller to provide a valid List[int]. This is standard for LeetCode solutions where input constraints are guaranteed by the judge.

Topics to Explore

Beliefs