DrawCode Practice Problem

Reverse Linked List

Given the head of a singly linked list, reverse the list and return the new head. (Implement `reverse_list(head)` where each node has `.val` and `.next`.)

Examples

Input

head = [1,2,3,4,5]

Output

[5,4,3,2,1]

Constraints


Interactive Visualizer Workspace

Explore step-by-step interactive animations, memory state tracking, and live multi-language execution in DrawCode.

Launch Interactive Visualizer