Solution: Odd Even Linked List
Explore the process of rearranging a singly linked list by grouping all nodes at odd indices first, followed by even indices, while maintaining their original relative order. Understand how to implement this in-place algorithm efficiently with O(n) time complexity and constant extra space. This lesson helps you master pointer manipulation for linked lists to solve similar problems in coding interviews.
We'll cover the following...
Statement
Given the head of a singly linked list, rearrange the nodes so that all nodes at odd indexes appear first, followed by all nodes at even indexes.
The first node in the list is considered at odd index 1, the second at even index 2, and so on.
Within the odd group and the even group, the relative order of the nodes must remain the same as in the original list.
Return the head of the reordered linked list.
Note: You must solve the problem in
...