Update appNew update is available. Click here to update.
sidenav-btnClose
Topic list
Reverse Alternate Nodes of a Singly Linked List
MEDIUM
5 upvotes
Linked List
Topics (Covered in this problem)
Problem solved
Badge
Skill meter
Linked List
-
-
Other topics
Problem solved
Badge
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
userLevel
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

Reverse Alternate Nodes of a Singly Linked List

Contributed by
Sounak Majumder
Medium
yellow-spark
0/80
Share
5 upvotes

Problem Statement

For a given Singly Linked List of integers, you are required to reverse alternate nodes and append them to the end of the list.

For Example:

The given linked list is 1->2->3->4 then after reversing the alternate nodes we will have 1->3->4->2. 

Assuming 0 based indexing, odd indexed nodes are the alternate nodes that is, in the given linked list the node with value 2 and the node with value 4 are the alternate nodes. 

List without alternate nodes:  1->3 
List with alternate nodes:  2->4 
Reversing the list with alternate nodes: 4->2

After appending the reversed alternate nodes at the end, the updated list will be 1->3->4->2. 
Detailed explanation ( Input/output format, Notes, Constraints, Images )
Sample Input 1 :
2 4 6 8 10 -1
Sample Output 1 :
2 6 10 8 4 -1
Explanation to Sample Input 1 :
The given linked list is 2->4->6->8->10 then after reversing the alternate nodes we will have 2->6->10->8->4.


Assuming 0 based indexing, odd indexed nodes are the alternate nodes that is, in the given linked list the node with value 4 and the node with value 8 are the alternate nodes. 

List without alternate nodes:  2->6->10 
List with alternate nodes:  4->8 
Reversing the list with alternate nodes: 8->4

After appending the reversed alternate nodes at the end, the updated list will be 2->6->10->8->4. 
Sample Input 2 :
-10 20 -1
Sample Output 2 :
 -10 20 -1
Reset Code
Full screen
Auto
copy-code
Console