Handle Score
@Ibrahim Nash 5725
@blackshadows 5685
@akhayrutdinov 5111
@mb1973 4989
@Quandray 4908
@saiujwal13083 4156
@sanjay05 3762
@marius_valentin_dragoi 3511
@sushant_a 3453
@KshamaGupta 3318
@the_coder95 3302
Complete Leaderboard
Rearrange a linked list
Easy Accuracy: 49.14% Submissions: 14534 Points: 2

Given a singly linked list, the task is to rearrange it in a way that all odd position nodes are together and all even positions node are together.
Assume the first element to be at position 1 followed by second element at position 2 and so on.

Example 1:

LinkedList: 1->2->3->4
Output: 1 3 2 4

Example 2:

LinkedList: 1->2->3->4->5
Output: 1 3 5 2 4

Your Task:
The task is to complete the function rearrangeEvenOdd() which rearranges the nodes in the linked list as required and return the head of the linked list.

Expected Time Complexity: O(N).
Expected Auxiliary Space: O(1).

1 <= Size of the linked list <= 10000
1 <= values of linked list<= 1000


to report an issue on this page.


We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?


All Submissions

My Submissions:

Login to access your submissions.

Rearrange a linked list

Output Window