Skip to content
DeepForgeby svx
All problems
HardData Structuresds-064

Reorder List

Problem

Reorder a linked list by interleaving the first half with the reversed second half.

The result follows L0, Ln-1, L1, Ln-2, ... until all nodes are used. The first half keeps the extra node when the length is odd.

Return the reordered values.

Hint

Split at the middle, reverse the second half, then alternate taking from each half.

Test cases

case 1
in: [[1,2,3,4]]
expected: [1,4,2,3]
case 2
in: [[1,2,3,4,5]]
expected: [1,5,2,4,3]
case 3
in: [[]]
expected: []
case 4
in: [[1]]
expected: [1]
Starter codePython
def reorder_list(values):
    # Your code here
    pass

4 test cases · run your code against them in the editor