Given the head of a singly linked list, group all the nodes with odd indices together followed by the nodes with even indices, and return the reordered list. The first node is considered odd, and the second node is even, and so on.
30:00
Java
Odd Even Linked List
medium
Topics
Companies
Given the head of a singly linked list, group all the nodes with odd indices together followed by the nodes with even indices, and return the reordered list. The first node is considered odd, and the second node is even, and so on.
Example 1:
Input: [1,2,3,4,5]
Output: [1,3,5,2,4]
Constraints:
n∈[0,104]
−106≤Node.val≤106
Input
arr =[1,2,3,4,5]
Group odd-indexed nodes together followed by even-indexed nodes