Sort Linked List Using Insertion Sort

Given the head pointer of a linked list, sort it in ascending order using insertion sort.

Statement

We’re given the head pointer of a linked list. Sort the linked list in ascending order using insertion sort. Return the new head pointer of the sorted linked list.

Example

If the given linked list is 29 -> 23 -> 82 -> 11, then the sorted list should be 11 -> 23 -> 29 -> 82.

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.