Zig-zag linked list
Your task
A singly linked list is given as a plain Python list of values. Reorder it in the classic zig-zag fold: L0 to Ln to L1 to Ln-1 to L2 to Ln-2 -> ... so the first node is followed by the last, then the second, then the second-to-last, and so on. Do it conceptually in-place (O(1) extra beyond the result). Return the reordered values as a Python list. The list has 0 to 10^5 elements.
Examples
reorder_fold(vals: list[int]) -> list[int]Example 1
Input
reorder_fold([1, 2, 3, 4, 5])Output
[1, 5, 2, 4, 3]