Zig-zag linked list
A singly linked list is given as a plain Python list of values. Reorder it in the classic zig-zag fold: L0 -> Ln -> L1 -> Ln-1 -> L2 -> 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.
Implement
reorder_fold(vals: list[int]) → list[int]Examples
in
[[1,2,3,4,5]]out[1,5,2,4,3]What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 25 min
solution.py
InputExpectedGot
[[1,2,3,4,5]][1,5,2,4,3]not run yetsample