Sort List
Sort a linked list in ascending order.
Examples
Input: [4,2,1,3]
Output: [1,2,3,4]
Input: [-1,5,3,4,0]
Output: [-1,0,3,4,5]
Hints
Identify the middle node of the linked list using the slow and fast pointer technique (tortoise and hare algorithm) to split the list into two halves.
Recursively apply the merge sort algorithm to the left and right halves of the linked list until each sublist contains a single node.
Merge the two sorted halves by comparing the nodes' values and rearranging the pointers to maintain the sorted order, ensuring the merged list is correctly linked.
Sort List
Sort a linked list in ascending order.