Basic traversal
Input
head = build_linked_list([1, 2, 3]) print_list(head)
Output
[1, 2, 3]
Visit nodes from head to tail and collect 1, then 2, then 3.
Full lesson preview
Traverse a singly linked list and collect its elements in order.
Problem statement
Task
Examples
Input
head = build_linked_list([1, 2, 3]) print_list(head)
Output
[1, 2, 3]
Visit nodes from head to tail and collect 1, then 2, then 3.
Input format
Output format
Constraints
Samples
Input
build_linked_list([5])
Output
[5]
Single-node list returns a list with that one value.