easy +8 pts

Reorder list halves

Join the first half and the reversed second half of a list into one list.

Write a function `reorder_list(nums: list) -> list` that takes a list of values (any type, but tests use numbers/strings) and returns a new list formed by: 1. Taking the first half of `nums` — defined as the elements from index `0` up to (but not including) `len(nums) // 2`. 2. Taking the second half — the remaining elements from index `len(nums) // 2` to the end. 3. Reversing that second half. 4. Concatenating the first half and the reversed second half. The original list must remain unchanged. If the list has fewer than 2 elements, return a copy of the original list (unchanged). The function should work for lists of any length, including empty lists.

Constraints

0 <= len(nums) <= 1000 The list may contain integers or strings. Time complexity: O(n), space complexity: O(n) for the output list.

Example

>>> reorder_list([1, 2, 3, 4, 5, 6])
[1, 2, 3, 6, 5, 4]
>>> reorder_list([1, 2, 3, 4, 5])
[1, 2, 5, 4, 3]
>>> reorder_list([])
[]
>>> reorder_list([1])
[1]
8 points ~10 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Find the middle index using integer division: `mid = len(nums) // 2`.
Slice the list into two parts: `first = nums[:mid]` and `second = nums[mid:]`.
Reverse the second part with `second[::-1]` or `reversed(second)`.
Concatenate the two parts and return the result.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.