Last Updated: 25 Feb, 2017

Rearrange odd and even places

Moderate
Asked in company
Rupeek

Problem statement

Rearrange and return a linked list in such a way that all odd position nodes are together and all even positions node are together

You just need to return the head of new linked list, don't print the elements.

Input format :
Line 1 : Linked list elements of length n (separated by space and terminated by -1)
Output format :
Updated list elements (separated by space)
Constraints :

1 <= n <= 10^4