Agoda processes some itinerary data as a singly linked list. Given the head of the list, return a Python list containing every odd-valued node, preserving the order in which the nodes appear.
Traverse the linked list once. Do not modify or reorder the linked list. If the list is empty or contains no odd values, return an empty list.
The input is head, either None or a reference to a singly linked-list node with two fields:
val: an integernext: a reference to the next node or NoneReturn a standard Python list of integers containing exactly the values for which value % 2 != 0.
For the examples and test cases, an input array such as [4, 7, 2] represents the linked list 4 -> 7 -> 2. The evaluation harness constructs the linked-list nodes before calling the function.
def get_odd_values(head):