Solution: Odd Even Linked List
Explore how to rearrange a singly linked list so that all nodes at odd indexes come before even indexed nodes while maintaining their relative order. Understand how to solve this efficiently using O(n) time and constant extra space by manipulating pointers in place.
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
extra space complexity and time complexity.
Constraints:
The number of nodes in the linked list is in the range
...