Solve a problem related to data structures, such as reversing a linked list.
Implement reverse_linked_list(head) for a singly linked list. Each node has val and next fields. Return the new head after reversing all links in place. The input and output are linked-list nodes, not arrays; array forms in the examples and tests represent serialized lists.
val field and a next field.def reverse_linked_list(head):