Reverse alternate nodes in Link List
Medium Accuracy: 50.78% Submissions: 11945 Points: 4

Given a linked list, you have to perform the following task:

  1. Extract the alternative nodes starting from second node.
  2. Reverse the extracted list.
  3. Append the extracted list at the end of the original list.

​Example 1:

LinkedList = 10->4->9->1->3->5->9->4
Output: 10 9 3 9 4 5 1 4
Explanation: Reversing the alternative
nodes from the given list, and then
appending them to the end of the list
results in a list with the elements as
10 9 3 9 4 5 1 4.

​Example 2:

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

Your Task:
You don't have to read input or print anything. Your task is to complete the function rearrange() which takes the head of the linked list as input and rearranges the list as required.

Note: Try to solve the problem without using any extra memory.

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

1 <= N <= 105
0 <= Node_value <= 1000

We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.

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.

Reverse alternate nodes in Link List

Output Window