Code Room
CodingMediumcod-g581
Subject Linked listsLevel Mid–Senior~25 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.