InterviewBit Academy is now Scaler!
InterviewBit Academy is now Scaler Academy!

Even Reverse


Problem Description

Given a linked list A , reverse the order of all nodes at even positions.



Problem Constraints

1 <= Size of linked list <= 100000



Input Format

First and only argument is the head of the Linked-List A.



Output Format

Return the head of the new linked list.



Example Input

Input 1:

A = 1 -> 2 -> 3 -> 4

Input 2:

A = 1 -> 2 -> 3



Example Output

Output 1:

 1 -> 4 -> 3 -> 2

Output 2:

 1 -> 2 -> 3



Example Explanation

Explanation 1:

Nodes are positions 2 and 4 have been swapped.

Explanation 2:

No swapping neccassary here.



NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Even Reverse on Interview Code Editor
Sign Up
to access hints and editorial solutions for Even Reverse
Asked In:

Discussion


Loading...
Click here to start solving coding interview questions