Odd even linked list

Write codeMedium20 min

Your task

Given a singly linked list as a plain list of values, group all nodes at odd positions together followed by the nodes at even positions, preserving the relative order within each group. Positions are 1-indexed (first node is odd). Return the reordered list of values. The list may be empty.

Examples

odd_even_list(values: list[int]) -> list[int]
Example 1
Inputodd_even_list([1, 2, 3, 4, 5])
Output[1, 3, 5, 2, 4]